Solved

Python + Mac: os.remove = Operation not permitted?

Posted on 2014-04-21
3
2,649 Views
Last Modified: 2014-04-21
It's simple: I have created a folder on the desktop that I later want to remove. But when I run the script, I get this:

Processing order from queue:  002508
Copying order to desktop: /Volumes/process/002508 -> /Users/Michael/Desktop/002508 
Traceback (most recent call last):
  File "./process-queue.py", line 64, in <module>
    prep_desktop()
  File "./process-queue.py", line 25, in prep_desktop
    os.remove(thefolder)
OSError: [Errno 1] Operation not permitted: '/Users/Michael/Desktop/TheFolder'

Open in new window


The file is owned by Michael:staff, and I can delete it manually by dragging into the trash can. I can delete it with rm -vf. I just can't delete it from within Python.

Please advise.
0
Comment
Question by:DrDamnit
3 Comments
 
LVL 31

Accepted Solution

by:
farzanj earned 500 total points
ID: 40012575
So you are trying

os.remove('/Users/Michael/Desktop/TheFolder')

Open in new window


Can you try this?
os.rmdir("/Users/Michael/Desktop/TheFolder")

Open in new window


Or this:
import shutil

shutil.rmtree('/Users/Michael/Desktop/TheFolder')

Open in new window

0
 
LVL 28

Expert Comment

by:pepr
ID: 40013041
A side note: The single or double quotes can be used interchangeably. They have the same functionality.

My +1 for shutil.rmtree, only the folder must not be a symblolic link. The os.rmdir works only for the empty directory. The os.remove can remove only the files.
0
 
LVL 32

Author Closing Comment

by:DrDamnit
ID: 40013290
Rmtree is the winner.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Trying to run a Python File 11 59
Cannot re-install OS X on a 2008 Mac desktop 17 103
Mac OS 10.12 + VPN 17 301
python question 5 60
In this article we have discussed about the OS X EI Capitan and how to fix Wi-Fi issue in OS X El Capitan. We have explained how to delete system level preferences and create a new Wi-Fi location to resolve Wi-Fi issue.
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now