Solved

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

Posted on 2014-04-21
3
2,956 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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
mixing mac for outlook and mac for windows 5 76
Lock session with OS X Sierra 1 59
Pixelmator App - Force Quit - NO! 2 60
Downgrading from Python 3.4.5 to 3.4.3 5 40
Flask is a microframework for Python based on Werkzeug and Jinja 2. This requires you to have a good understanding of Python 2.7. Lets install Flask! To install Flask you can use a python repository for libraries tool called pip. Download this f…
In this article we will discuss some EI Capitan Mail app issues and provide some manual process to resolve them.
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 …
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

770 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