python cycle through files in folder 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"):
continue
else:
continue
Example 2: traverse files in directory python
import os
for dirpath, dirnames, filenames in os.walk(dir_path):
print(dirpath)
print(dirnames)
print(filenames)
import os.path
def print_it(x, dir_name, files):
print(dir_name)
print(files)
os.path.walk(your_dir, print_it, 0)