Python Forum
os.remove() Access is denied
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
os.remove() Access is denied
#2
If you have a file, you can remove just that file with os.remove() or os.unlink(). Similar to /bin/rm, this function fails on directories.

If you have a (empty) directory, you can remove it with os.rmdir(). Similar to /bin/rmdir.

If you have a path and want it and everything underneath it removed if possible, you can do so with shutil.rmtree(). Similar to /bin/rm -r.

Also, older documentation stated that os.remove() would throw an OSError if it were handed a directory. Newer documentation states flatly that it now throws a IsADirectoryError. But it looks like that may be OS dependent. I do see the newer error on Linux, but I don't on MacOS (which still throws OSError, even on 3.8). I'm guessing that Windows does the same, but I can't test that immediately.

Linux/Python 3.7.4
>>> os.remove("dir")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IsADirectoryError: [Errno 21] Is a directory: 'dir'
MacOS/Python 3.8.2
>>> os.remove("dir")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
PermissionError: [Errno 1] Operation not permitted: 'dir'
Reply


Messages In This Thread
os.remove() Access is denied - by pythonnewbie138 - Aug-28-2020, 08:33 PM
RE: os.remove() Access is denied - by bowlofred - Aug-28-2020, 08:55 PM
RE: os.remove() Access is denied - by bowlofred - Aug-28-2020, 10:02 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  The INSERT permission was denied on the object Steven5055 2 1,538 Feb-25-2023, 11:37 PM
Last Post: Steven5055
  access is denied error 5 for network drive mapping ? ahmedbarbary 2 1,837 Aug-17-2022, 10:09 PM
Last Post: ahmedbarbary
  Server Folder Error : WinError5 Access Denied fioranosnake 1 1,156 Jun-21-2022, 11:11 PM
Last Post: Larz60+
  Error no 13: Permission denied in python shantanu97 1 6,247 Mar-31-2021, 02:15 PM
Last Post: snippsat
  Access denied not able to do anything 8( What do i do? MurphysLaw 3 3,840 Oct-20-2020, 08:16 AM
Last Post: snippsat
  Fixing "PermissionError: [Errno 13] Permission denied" puredata 17 72,930 Mar-09-2020, 03:20 PM
Last Post: syssy
  Has anyone experience a winError[5] Access Denied in Windows 10? fstkmaro 2 13,021 Nov-11-2019, 02:38 PM
Last Post: fstkmaro
  PermissionError: [Errno 13] Permission denied: error leviathan54 2 46,742 Apr-20-2019, 12:51 AM
Last Post: leviathan54
  [python] PermissionError: [Errno 13] Permission denied akamouch 1 42,488 Feb-07-2019, 03:28 PM
Last Post: ichabod801
  getting [Errno 13] Permission denied: gobinath 1 7,084 Jan-29-2019, 05:36 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020