Answers for "python for file in 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
3

python open each file in directory

import os
for filename in os.listdir(os.getcwd()):
   with open(os.path.join(os.cwd(), filename), 'r') as f:
Posted by: Guest on July-03-2020
5

how to search for a specific file extension with python

import glob, os
os.chdir("/mydir")
for file in glob.glob("*.txt"):
    print(file)
Posted by: Guest on March-06-2020
12

get files in directory python

import os
files_and_directories = os.listdir("path/to/directory")
Posted by: Guest on June-12-2020
0

python iterate 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 October-26-2020
0

how to make all my files to work together in python

>>> import os
>>> entries = os.listdir('my_directory/')
Posted by: Guest on September-03-2020

Code answers related to "python for file in directory"

Python Answers by Framework

Browse Popular Code Answers by Language