文件copy总结:
import os
src_path = r'E:\Users\Python\example0514\day0515\image'
target_path =r'E:\Users\Python\example0514\day0515\movies'
def copy_file(src_path,target_path):
filelist = os.listdir(src_path)
for file in filelist:
path = os.path.join(src_path,file)
if os.path.isdir(path):
# 递归调用
#os.chdir(target_path)
if os.path.exists(os.path.join(target_path,file)):
pass
else:
os.mkdir(os.path.join(target_path,file))
target_path1 = os.path.join(target_path,file)
print(target_path1)
copy_file(path,target_path1)
else:
with open(path,'rb') as rstream:
container = rstream.read()
path1 = os.path.join(target_path,file)
with open(path1,'wb') as wstream:
wstream.write(container)
else:
print('复制完成')
copy_file(src_path,target_path)