python glob loop through files code example
Example 1: iterate through all files in directory python
import os
directory = 'the/directory/you/want/to/use'
for filename in os.listdir(directory):
if filename.endswith(".txt"):
#do smth
continue
else:
continue
Example 2: how to loop through glob.iglob iterator
import glob
globIterator = glob.iglob(path, recursive=True)
run = True
while(run == True):
try:
print(next(globIterator))
except:
run = False