What's new

display a progress bar while copy files using tqdm in python

Fever

Active member
Staff member
I have a python script that copy folders and files existing in a selected place. This task work perfect, now i want to display a progress bar while copying.

I used tqdm package that display the progress bar in the console, and it work good but the problem is that it display the progress bar on each files and walk over the all the existing files each time .

example : having a folder includes 128 files it will display the progress bar 128 time like this

100%---------128/128 100%---------128/128
what i want is to display the progress bar 1 time for all files being copied.

where is the error in my below code ?

i=0
j=0
z=0
for dirpath, dirnames, files in os.walk(src):
print(f'Found directory: {dirpath}')
if len(dirnames)==0 and len(files)==0:
print("this directory is empty")
pass

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")
#copy files pdf moula5asat
shutil.copy(full_file_name, dst2)
i+=1

elif file.endswith("docx") or file.endswith("doc"):
#copy files DOCX
shutil.copy(full_file_name, dst)
j+=1

elif os.path.join(dirpath)== src2:
if file.endswith("pdf"):
numfile = len(files)

for z in enumerate(tqdm(numfile)):
sleep(.1)
# #copy files PDF TO WASIKA
shutil.copy(full_file_name, dst3)
z+=1

Continue reading...
 
Top