只限于当前路径的
import os
from multiprocessing import Pool, Manager
# copy 文件
def work_copy_file(file, olderFileName, newFileName, queue):
# 首先打开一个文件
fread = open(olderFileName + "/" + file, "r", encoding='UTF-8')
fwrite = open(newFileName + "/" + file, "w", encoding='UTF-8')
content = fread.read()
fwrite.write(content)
fread.close()
fwrite.close()
queue.put(file)
pass
def main():
olderFileName = input("请输入您的文件名字")
newFileName = olderFileName + "-复制文件"
os.mkdir(newFileName) # 创建新文件
olderFileNames = os.listdir(olderFileName) # 列出文件夹中所有的数据
# 在进程池中进行操作
p = Pool(5)
queue = Manager().Queue()
for file in olderFileNames:
p.apply_async(work_copy_file, (file, olderFileName, newFileName, queue))
num = 0
allNum = len(olderFileNames)
while num != allNum:
queue.get()
num += 1
copyRate = num / allNum
print("进度是", copyRate * 100, )
print('完成了')
if __name__ == '__main__':
main()