Avatar of DrDamnit
DrDamnit
Flag for United States of America asked on

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

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.
PythonMac OS X

Avatar of undefined
Last Comment
DrDamnit

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
farzanj

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
pepr

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.
DrDamnit

ASKER
Rmtree is the winner.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck