Skip to content

Instantly share code, notes, and snippets.

@wangg12
Forked from whophil/recursive_glob.py
Created August 2, 2018 02:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wangg12/d6dc0352dbba6fafb9f5fe8c8f5e4b78 to your computer and use it in GitHub Desktop.
Save wangg12/d6dc0352dbba6fafb9f5fe8c8f5e4b78 to your computer and use it in GitHub Desktop.
Recursive glob in Python: Find all files matching a glob-style pattern. Adapted from http://stackoverflow.com/a/2186565/6191541
import os
import fnmatch
def recursive_glob(rootdir='.', pattern='*'):
"""Search recursively for files matching a specified pattern.
Adapted from http://stackoverflow.com/questions/2186525/use-a-glob-to-find-files-recursively-in-python
"""
matches = []
for root, dirnames, filenames in os.walk(rootdir):
for filename in fnmatch.filter(filenames, pattern):
matches.append(os.path.join(root, filename))
return matches
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment