Oct-28-2019, 10:59 PM
(This post was last modified: Oct-28-2019, 11:00 PM by ConsoleGeek.)
I'm attempting to copy the Documents folder under the Windows userprofile, the
I also posted this question on Stack Overflow, but no one has answered.
shutil.copytree(documents, destination) works partially. It will copy the Documents to the root of the destination, in this case the R: drive, and it will also attempt to copy the other Windows special folders (My Music, My Pictures, etc..), even if they don't exist under Documents.import shutil
def main():
try:
user_profile = os.getenv("USERPROFILE")
# Construct a full path to the documents folder
documents = Path(user_profile).joinpath("Documents")
# Destination for the Documents folder
destination = Path("R:\\Test")
shutil.copytree(documents, destination)
except (FileNotFoundError, shutil.Error) as error:
print(error)
if __name__ == '__main__':
main()This is a excerpt of the exception that is thrown:[('C:\\Users\\ConsoleGeek\\Documents\\My Music', 'R:\\Test\\My Music',
"[WinError 5] Access is denied: 'C:\\\\Users\\\\ConsoleGeek\\\\Documents\\\\My Music'")
...None of these folders exist under Documents, so I don't fully understand why shutil attempts to copy these special folders. If I attempt to copy a regular folder under the user profile, it works.I also posted this question on Stack Overflow, but no one has answered.
