I have a python script that read from source folder and copy existing files into the specified destination using shutil package.
I want to show a progress bar while copying these files so i tried to import tqdm package, but when i try to run the program it crash and display the below error:
for obj in iterable : typeError: 'int' object is not iterable
#packages for list and copy folders & files.
import calendar
import os
import shutil
from os import path
from datetime import date
#packags for progressBar
from tqdm import tqdm
from time import sleep
def main():
copy("O:/PDF/")
dst3 = "C:/Users/gmatta/Documents"
def copy(src):
src2 = os.path.join(src, datefile)
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)== src2:
if file.endswith("pdf"):
numfile = len(files)
# the problem is in the 2 lines below
for z in enumerate(tqdm(numfile)):
sleep(.1)
# #copy files PDF TO dest
shutil.copy(full_file_name, dst3)
z+=1
if __name__=="__main__":
main()
tqdm
expects an iterable argument.
In this line in your code
for z in enumerate(tqdm(numfile)):
numfile
is an integer.
Try using range(numfile)
perhaps?