1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
import os import multiprocessing.process
def (file_name,src_path,dest_path): path = src_path + "/" + file_name new_path = dest_path + "/" + file_name if os.path.isfile(path): print(path + " --> ./" + new_path) r_file = open(path,"rb") w_file = open(new_path,"wb") while 1: data = r_file.read(4096) if not data: break w_file.write(data) r_file.close() w_file.close() else: file_list = os.listdir(path) os.mkdir(new_path) for file_name in file_list: copy_file(file_name,path,new_path)
def main(): src_path = input("请输入要拷贝的文件夹:") dest_path = src_path + "-备份" if os.path.exists(src_path): if not os.path.exists(dest_path): os.mkdir(dest_path) file_list = os.listdir(src_path) pool = multiprocessing.Pool(5) for file_name in file_list: pool.apply_async(copy_file,args = (file_name,src_path,dest_path)) pool.close() pool.join() print("文件拷贝完成") else: print("要拷贝的文件夹%s不存在!"%src_path)
if __name__ == "__main__": main()
|
近期评论