Answers for "python iterate through multiple files in a folder"

20

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
0

how to read multiple files in a loop in python

import numpy as np
files = ["a.txt", "b.txt"]
for file in files:
  print(np.loadtxt(file, skiprows=1))
Posted by: Guest on October-25-2021

Code answers related to "python iterate through multiple files in a folder"

Python Answers by Framework

Browse Popular Code Answers by Language