python get every file in directory code example

Example 1: for every file in the folder do python

for file in os.listdir(inputdir):

Example 2: how to search for a specific file extension with python

import glob, os
os.chdir("/mydir")
for file in glob.glob("*.txt"):
    print(file)

Example 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:

Example 4: os list all files in one dir

import glob
print(glob.glob("/home/adam/*.txt"))

Example 5: list files python

import glob
files=glob.glob(given_path)

Example 6: list files python

#get all .txt files in my_path
import glob
my_path='/home/folder/'
files=glob.glob(my_path+'*.txt')