zoukankan      html  css  js  c++  java
  • python 文件夹拷贝

    文件夹拷贝器_同步方式

    import os
    
    
    def copy_work(source, dest, name):
        source_path = source + "/" + name
        dest_path = dest + "/" + name
        with open(source_path, "rb") as f:
            with open(dest_path, "wb") as f2:
                while True:
                    buff = f.read(1024)
                    print(buff)
                    if buff:
                        f2.write(buff)
                    else:
                        break
    
    
    if __name__ == '__main__':
        source_dir = "./test"
        dest_dir = "./home"
    
        try:
            os.mkdir(dest_dir)
        except Exception as e:
            print(e)
    
        try:
            file_list = os.listdir(source_dir)
            for file_name in file_list:
                copy_work(source_dir, dest_dir, file_name)
        except Exception as e:
            print(e)
    
    

    文件夹拷贝器_多进程异步方式_

    import os
    import multiprocessing
    
    
    def copy_work(source, dest, name):
        print(multiprocessing.current_process())
        source_path = source + "/" + name
        dest_path = dest + "/" + name
        with open(source_path, "rb") as f:
            with open(dest_path, "wb") as f2:
                while True:
                    buff = f.read(1024)
                    print(buff)
                    if buff:
                        f2.write(buff)
                    else:
                        break
    
    
    if __name__ == '__main__':
        source_dir = "./test"
        dest_dir = "./home"
    
        try:
            os.mkdir(dest_dir)
        except Exception as e:
            print(e)
    
        try:
            pool = multiprocessing.Pool(3)
            file_list = os.listdir(source_dir)
            for file_name in file_list:
                pool.apply_async(copy_work,(source_dir, dest_dir, file_name))
            pool.close()
            pool.join()
        except Exception as e:
            print(e)
    
    
  • 相关阅读:
    [湖南集训]谈笑风生
    【SCOI2010】序列操作
    ●BZOJ 3994 [SDOI2015]约数个数和
    ●BZOJ 3309 DZY Loves Math
    ●UOJ 21 缩进优化
    ●BZOJ 2693 jzptab
    ●BZOJ 2154 Crash的数字表格
    ●BZOJ 3529 [Sdoi2014]数表
    ●2301 [HAOI2011] Problem b
    ●BZOJ 2820 YY的GCD
  • 原文地址:https://www.cnblogs.com/lautung/p/13878227.html
Copyright © 2011-2022 走看看