iterate through directories python code example
Example 1: how to loop through files in a directory python
import os
for filename in os.listdir(directory):
if filename.endswith(".asm") or filename.endswith(".py"):
# print(os.path.join(directory, filename))
continue
else:
continue
Example 2: python loop through files in directory recursively
import os
rootdir = './path/to/files/'
for subdir, dirs, files in os.walk(rootdir):
for file in files:
print os.path.join(subdir, file)