#coding=utf-8
from multiprocessing import Pool,Queue
import os,time
filename = os.listdir("./test1")
#创建Queue队列
queue = Queue(len(filename))
def copyFile(i):
#实现文件复制
oldFileName = "./test1/" + i
newFileName = "./test2/" + i
oldfile = open(oldFileName,'r')
newfile = open(newFileName,'w')
for lineContent in oldfile.readlines():
newfile.write(lineContent)
oldfile.close()
newfile.close()
if __name__ == '__main__':
pool = Pool(4)
for i in filename:
pool.apply_async(copyFile,(i,))
#队列中将copy完成的文件放入队列中并打印进度
queue.put(i)
price = str(int((queue.qsize()/len(filename))*100))
print('\r'+' '*60,end='')
print('\r'+price+'%'+'=======>%s'%i,end='')
time.sleep(0.07)
print('')
pool.close()
pool.join()