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学习\day19\ceshi',type='dir1')

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM