for files in folder python code example
Example 1: for every file in the folder do python
for file in os.listdir(inputdir):
Example 2: python iterate through files in directory
import os
for filename in os.listdir(directory):
if filename.endswith(".asm") or filename.endswith(".py"):
continue
else:
continue
Example 3: python loop opening file from directory
basepath = "pathtodir/DataFiles/"
for filename in os.listdir(basepath):
if filename.endswith(".log"):
print(os.path.join("./DataFiles", filename))
with open(basepath + filename) as openfile:
for line in openfile:
........