MegaMU个人站

欢迎光临

落日黄沙 白帆秋水 你可知谁的记忆在时空里飞?


项目:文件copy器

目录

import os
import multiprocessing

def copy_work(source_dir,dest_dir,file_name):
    print(multiprocessing.current_process())
    source_path = source_dir+"/"+file_name
    dest_path = dest_dir+ "/"+file_name
    print(source_path,"------>",dest_path)
    with open(source_path,"rb") as source_file:
        with open(dest_path,"wb") as dest_file:
            while True:
                file_data = source_file.read(1024)
                if file_data :
                    dest_file.write(file_data)
                else:
                    break

if __name__ == "__main__":
    source_dir =input()
    dest_dir ="./dest"

    try:
        os.mkdir("./dest")
    except Exception as e:
        print("文件已存在!")

    file_list = os.listdir("./test")
    print(file_list)

    pool = multiprocessing.Pool(3)

    for file_name in file_list:
        print(file_name)
        pool.apply_async(copy_work,(source_dir,dest_dir,file_name))
    pool.close()
    pool.join()
    pass

未完待续

打赏一个呗

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦