Reputation: 614
i try to copy a directory (divided into folders and subfolders) to a new folder that will be created.i work with python 2.7.
I read https://docs.python.org/2/library/shutil.html and tried this code:
import os,shutil
dir_src = r"C:\Project\layers"
dir_dst = r"C:\Project\new"
for file in os.listdir(dir_src):
print file
src_file = os.path.join(dir_src, file)
dst_file = os.path.join(dir_dst, file)
shutil.copytree(src_file, dst_file,symlinks=False, ignore=None)
print 'copytree'
But i get an error:
WindowsError: [Error 267] : 'C:\\Project\\layers\\abc.cpg/*.*'
Thank you very much for any help.
Upvotes: 0
Views: 980
Reputation: 1954
About edited question and error:
WindowsError: [Error 267] : 'C:\\Project\\layers\\abc.cpg/*.*'
Please carefully read docs
import shutil
dir_src = r"C:\Project\layers"
dir_dst = r"C:\Project\new"
shutil.copytree(dir_src, dir_dst)
you not need any for.
Note: Please keep in mind, that destination path shouldn't be existed.
Upvotes: 0
Reputation: 538
The error you are getting (Permission denied
) should tell you what is the problem - you don't have rights to read or copy the files. Running the program as administrator should fix it.
Upvotes: 1