Answers for "iterate over folders in python"

1

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))
Posted by: Guest on December-25-2020
1

python iterate directory

import os

directory = r'C:Usersadmin'
for filename in os.listdir(directory):
    if filename.endswith(".jpg") or filename.endswith(".png"):
        print(os.path.join(directory, filename))
    else:
        continue
Posted by: Guest on February-22-2021

Code answers related to "iterate over folders in python"

Python Answers by Framework

Browse Popular Code Answers by Language