Find All Files in Directory and Subdirectories using Python

glob.iglob function

import glob
import os

rootDir = 'test_dir'

files = []

for filePath in glob.iglob(rootDir + '**/**', recursive=True):
    if os.path.isfile(filePath):
        files.append(filePath)

print(files)

Leave a Comment

Cancel reply

Your email address will not be published.