python foreach file in folder code example
Example 1: python loop through files in directory
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: how to search for a specific file extension with python
import glob, os
os.chdir("/mydir")
for file in glob.glob("*.txt"):
print(file)