I used os.rename() method to rename the directory in my python script. This script called automatically by the scheduler every day. Sometimes the os.rename() function returns the error,
[Error 5] Access is denied
But all other times its working fine. Code,
try:
if(os.path.exists(Downloaded_Path)):
os.rename(Downloaded_Path, Downloaded_Path + "_ByClientTool")
except Exception,e:
print "Error !!", str(e)
return 1
I had a similar problem on Windows 10: sometimes my python script could not rename a directory even though I could manually rename it without a problem.
I used Sysinternal's handle.exe tool to find that explorer.exe had a handle to a sub-directory of the directory I was trying to rename. It turns out explorer was adding this sub-directory to its "Quick Access" section which prevented my script from renaming the folder.
I wound up disabling the "Show frequently used folders in Quick access" option from Explorer -> View -> Options -> General -> Privacy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With