Last active
August 2, 2018 02:55
-
-
Save whophil/2a999bcaf0ebfbd6e5c0d213fb38f489 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
You could also write a recursive version of iglob like this: