When using python os.rmdir get PermissionError: [WinError 5] Access denied

I am creating a script file transfer, and the source cleanup function uses os.rmdir('C:\\Users\\Grav\\Desktop\\TestDir0\\Om') . This is the error I get:

 PermissionError: [WinError 5] Access is denied: 'C:\\Users\\Grav\\Desktop\\TestDir0\\Om' 

I checked the permissions on the Om folder through Windows 7 and they are set to delete for my user account. I also tried to configure my interpreter to work as an administrator. The problem persists, and I am at an impasse. It is very important that someone with understanding!

+5
source share
3 answers

I found a solution here: Which user runs python scripts, like on Windows?

It seems that the folder with the violation has a stubborn read-only attribute. Adding read-only flags to the handler to change such checkboxes worked like a charm to me.

Everyone who posted suggestions helped me track the final answer, so thanks!

+2
source

You can check:

  • You are not in the 0m directory and run the script from there.
  • You have no windows open in the 0m list.
  • Since 0m is a subdirectory of TestDir0 , you have the correct permissions for TestDir0
+1
source

I had the same problem, I could do it through the shutil module.

 import shutil shutil.rmtree('/path/to/your/dir/') 
+1
source

Source: https://habr.com/ru/post/1246253/


All Articles