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')