python how to loop through folders 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"):
continue
else:
continue
Example 2: python loop through all folders and subfolders
directory = "c:\\folder\\you\\want\\to\\work_on"
for root, subdirectories, files in os.walk(directory):
for subdirectory in subdirectories:
print(os.path.join(root, subdirectory))
for file in files:
print(os.path.join(root, file))