I have researched the similarly asked questions without prevail. I am trying to os.walk() a file tree copying a set of files to each directory. Individual files seem to copy ok (1st iteration atleast), but an error is thrown (IOError: [Errno 13] Permission denied: 'S:/NoahFolder\\.images') while trying to copy a folder (.images) and its contents? I have full permissions to this folder (I believe).
What gives?
import os
import shutil
import glob
dir_src = r'S:/NoahFolder/.*'
dir_dst = r'E:/Easements/Lynn'
src_files = glob.glob(dir_src)
print src_files
for path,dirname,files in os.walk(dir_dst):
for item in src_files:
print path
print item
shutil.copy(item, path)
shutil.copy
will only copy files, not directories. Consider using shutil.copytree
instead, that's what it was designed for.
This implementation of copytree seemed to get it done! Thanks for the input @ holdenweb
from distutils.dir_util import copy_tree
for path,dirname,files in os.walk(dir_dst):
for item in src_files:
try:
shutil.copy(item, path)
except:
print item
print path
copy_tree(dir_src, path)
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.