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
code:
JavaScript
x
43
43
1
#packages for list and copy folders & files.
2
import calendar
3
import os
4
import shutil
5
from os import path
6
from datetime import date
7
8
#packags for progressBar
9
from tqdm import tqdm
10
from time import sleep
11
12
13
def main():
14
copy("O:/PDF/")
15
16
17
dst3 = "C:/Users/gmatta/Documents"
18
19
def copy(src):
20
src2 = os.path.join(src, datefile)
21
z=0
22
for dirpath, dirnames, files in os.walk(src):
23
print(f'Found directory: {dirpath}')
24
if len(dirnames)==0 and len(files)==0:
25
print("this directory is empty")
26
pass
27
28
for file in files:
29
full_file_name = os.path.join(dirpath, file)
30
31
if os.path.join(dirpath)== src2:
32
if file.endswith("pdf"):
33
numfile = len(files)
34
35
# the problem is in the 2 lines below
36
for z in enumerate(tqdm(numfile)):
37
sleep(.1)
38
# #copy files PDF TO dest
39
shutil.copy(full_file_name, dst3)
40
z+=1
41
if __name__=="__main__":
42
main()
43
Advertisement
Answer
tqdm
expects an iterable argument.
In this line in your code
JavaScript
1
2
1
for z in enumerate(tqdm(numfile)):
2
numfile
is an integer.
Try using range(numfile)
perhaps?