python21 - 云代码空间
——
#利用闭合函数来完成文件的复制
import os car_python1=r'D:\文档\python1'#源文件的地址 car_python2=r'D:\文档\python2'#复制后的文件的地址 def copy(car_,bas_): filelist=os.listdir(car_) for file in filelist: path=os.path.join(car_,file) if os.path.isdir(path): copy(path,bas_)#运用了递归函数 pass else: with open(path,'rb') as strena: wen=strena.read() path2=os.path.join(bas_,file) with open(path2,'wb') as wstrean: rii=wstrean.write(wen) print(rii) else: print('完成复制') copy(car_python1,car_python2)