-
-
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
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