Skip to content
Home » Can’t remove a folder with os.remove WindowsError: [Error 5] Access is denied

Can’t remove a folder with os.remove WindowsError: [Error 5] Access is denied

To solve Can’t remove a folder with os.remove WindowsError: [Error 5] Access is denied: error follow below methods.

ERROR LOG

Can’t remove a folder with os.remove (WindowsError: [Error 5] Access is denied: ‘c:/temp/folder’)

How to solve Can’t remove a folder with os.remove WindowsError: [Error 5] Access is denied: ?

Refer to the given methods to solve the issue.

Method 1:

The os.remove requires a file path and if you provide a path is a directory then it raises OSError 

You can try os.rmdir('path/to/folder') to remove a folder

os.rmdir('path/to/folder')

Method 2 :

You can also try shutil to remove a directory or a folder. Use:

shutil.rmtree("path/tofolder")

Hope the above solution works.

Also read : TypeError: must be str not bytes with pickle.dump()