I have created a Python script, whose goal is to copy Windows user folders (Downloads, Desktop, Music and so on...) to a USB drive.
def copyFolders():
userPath = f"C:\\Users\\{user}\\"
priorityLs = ["Music", "Documents", "Desktop", "Downloads", "Pictures", "Videos"]
permissionErrors = 0
permissionGrant = 0
removedElems = 0
for i in range(len(priorityLs)):
print("Copying...")
try: copy2(userPath+priorityLs[i], usbDrive)
except PermissionError: print(Fore.RED+f"Permission error! {Fore.WHITE[{userPath+priorityLs[i]}]{Fore.RESET}"); permissionErrors += 1
else: permissionGrant += 1
print(f"Permission grants: {permissionGrant} | Permission errors: {permissionErrors} | Removed elements: {removedElems}")
However, upon execution, I keep getting PermissionError. This confuses me, since even running the script with administrator rights throws the error, and those folders aren't encrypted.
Malware is easily capable of accessing to those folders to cipher them.
I have tried, as I mentionned above to run the script as admin, but same thing. Literally no folder can be copied.
I have looked at a question, asking why shutil.copy2 cannot copy to different drives, but it has no answers.
Here is the error traceback:
Traceback (most recent call last): File "e:\Code\Python\mainscr.py", line 152, in <module>
copyFolders() File "e:\Code\Python\mainscr.py", line 108, in copyFolders
copy2(userPath+priorityLs[i], usbDrive) File "C:\Users\name\AppData\Local\Programs\Python\Python310\lib\shutil.py", line 434, in copy2
copyfile(src, dst, follow_symlinks=follow_symlinks) File "C:\Users\name\AppData\Local\Programs\Python\Python310\lib\shutil.py", line 254, in copyfile
with open(src, 'rb') as fsrc: PermissionError: [Errno 13] Permission denied: 'C:\\Users\\name\\Videos'