Reputation: 21
I have tried to use shutil.move() to move a collection of files individually from their directory in one drive to another drive and it appears to succeed on copying the first file, however when it comes to delete the remove it runs into a permission error:
PermissionError: [WinError 5] Access is denied: 'C:\\Program Files\\openPDC\\Archive\\ppa_archive_2020-03-04 15!25!29.120_to_2020-03-04 20!16!30.900.d'
I am able to manually delete the file by hand using admin privledge but I am unsure on how to invoke admin privledge within the Python script to allow the shutil.move() to the remove the original file. I have tried to remove the read-only access but that doesn't seem to help, any ideas?
try:
os.chmod(files[i], stat.S_IWRITE )
os.unlink(files[i])
shutil.move(files[i], destination)
except PermissionError:
print ("Error: Could not move file {} from {} to {}".format(files[i], source, destination))
raise
Upvotes: 1
Views: 1818
Reputation: 21
To solve this issue, rather than over complicate the code I found it easiest to go into the original directories Properties -> Security -> Edit and then select my user group and allow full control of the files within the directory.
After that moving the files caused no issue.
Upvotes: 1