【发布时间】:2020-06-24 20:44:05
【问题描述】:
我有一个列出文件和目录并复制所需的脚本。现在我需要添加一个进度条来显示使用tqdm包
的复制进度问题是我不知道在哪里对 tqdm 进行迭代以获得我想要的结果。
代码:
numfile = len(files)
for file in files:
full_file_name = os.path.join(dirpath, file)
if os.path.join(dirpath) == src:
if file.endswith("pdf"):
if not os.path.exists(dst2):
os.mkdir(dst2)
else:
print("the path alredy exist")
shutil.copy(full_file_name, dst2)
i+=1
elif file.endswith("docx") or file.endswith("doc"):
shutil.copy(full_file_name, dst)
j+=1
elif os.path.join(dirpath)== src2:
if file.endswith("pdf"):
shutil.copy(full_file_name, dst3)
z+=1
for z in tqdm(range(numfile)):
sleep(.1)
print("*******number of directories = {}".format(len(dirnames)))
print("*******number of files = {}".format(len(files)))
现在它复制文件而不是显示进度条。
我想要的是在复制时显示进度条
【问题讨论】:
-
为什么不在第二行用 tqdm 包装文件?
-
@MercyDude 你是什么意思?
-
为什么不把第二行改成“for file in tqdm(files):”
标签: python copy progress-bar