import shutil
#复制文件
shutil.copyfile('listfile.py', 'd:/test.py')
#复制目录
shutil.copytree('d:/temp', 'c:/temp/')
#其余可以参考shutil下的函数
import shutil
import os
def my_copy(path1,path2,type='file'):
if type == 'file':
shutil.copyfile(path1,path2)
print('文件复制成功')
elif type == 'dir1':
shutil.copytree(path1,path2)
print('目录复制成功')
return
# 复制test2里面的test文件到day19下面
my_copy('E:\Python学习\day18\\test\\test2\\test','E:\Python学习\day19\\test')
# 复制目录test及其test2及test到文件day19下面,命名:ceshi
my_copy('E:\Python学习\day18\\test','E:\Python学习\day19\ceshi',type='dir1')