Answers for "python loop directory"

17

iterate through all files in directory 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
10

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
Posted by: Guest on May-11-2020
0

python loop through directory

import os

for filename in os.listdir(directory):
	print(filename)
Posted by: Guest on October-01-2021

Code answers related to "python loop directory"

Python Answers by Framework

Browse Popular Code Answers by Language