xyzio

Recursively get all file names from a directory

leave a comment »

Recursively get all file names matching a substring from a directory.

Where:
* path = Directory to search
* matchStr = Substring to match

import os
import fnmatch

def getFiles(path, matchStr):
matches = []
for root, dirnames, filenames in os.walk(path):
    for filename in fnmatch.filter(filenames, matchStr):
        matches.append(os.path.join(root, filename))

return matches

Written by M Kapoor

April 12, 2015 at 2:21 pm

Posted in python

Leave a comment