I'm trying to run a script (with admin privileges) that deletes a specific directory (using shutil.rmtree
). Now, some of its files raises the following error:
WindowsError: [Error 5] Access is denied
When I delete it using Windows Explorer, it succeeds with no errors.
How can I delete the whole folder using shutil.rmtree
without the errors?
I found out that I can use win32api.SetFileAttributes(filepath, win32con.FILE_ATTRIBUTE_NORMAL)
to a specific file which fixes the error issue.
Is there a way to do it for the whole folder, or is there another way to delete the whole folder with no errors that I'm missing here?