Answers for "python for loop through folders in a folder"

17

how to iterate through files in a folder python

import os
directory = 'the/directory/you/want/to/use'

for filename in os.listdir(directory):
    if filename.endswith(".txt"):
      #do smth
      continue
    else:
    continue
Posted by: Guest on March-30-2020
1

python iterate directory

import os

directory = r'C:\Users\admin'
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 "python for loop through folders in a folder"

Python Answers by Framework

Browse Popular Code Answers by Language