python list all files in directory and subdirectories with extension code example

Example 1: 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 2: python list all files in directory

from os import listdir
from os.path import isfile, join
onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]

Example 3: bash list all files in directory and subdirectories

# Bash-specific

# syntax 
ls -R <file-or-directory-to-find>

# example
ls -R *hotographi*