python实现复制整个目录的方法

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学习day19ceshi',type='dir1')
原文地址:https://www.cnblogs.com/apollo1616/p/9513486.html