import shutil
import os
import time
os.chdir('c:\\User\\user\\')
time.sleep(10)
shutil.copytree('Pictures', 'E:\\')
So I have wasted all day just so I can steal files from my friend but no matter what I do nothing f*** works... Sorry for being angry but for crying out loud... I am a beginner so I haven't experienced the hell programmers go trough. Ty for helping!
To get your problem solved, it is a good idea to report the error message that you get , which was PermissionError: [WinError 5] Access is denied: 'E:\\'.
The docs for shutil.copytree()
say
Recursively copy an entire directory tree rooted at
src
to a directory nameddst
and return the destination directory.dirs_exist_ok
dictates whether to raise an exception in casedst
or any missing parent directory already exists
This makes it clear that you have to name a fresh target folder and that this should normally not exist.
Using os.chdir()
overcomplicates things. All you have to do is specify the full path of the source folder and the full path of the new target folder in your call to copytree()
, so that you end up with a 2-line program, like this:
import shutil
shutil.copytree(r"C:\Users\user\Pictures",r"E:\mynewdir")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.