Skip to content

Instantly share code, notes, and snippets.

@josephcoombe
Created February 7, 2020 03:49
Show Gist options
  • Save josephcoombe/3b1f337fee25c4051befc4b194c85396 to your computer and use it in GitHub Desktop.
Save josephcoombe/3b1f337fee25c4051befc4b194c85396 to your computer and use it in GitHub Desktop.
Recursive glob for Python 2
# References:
# https://stackoverflow.com/a/2186639/8670609
import os
import fnmatch
def recursive_glob(treeroot, pattern):
results = []
for base, dirs, files in os.walk(treeroot):
goodfiles = fnmatch.filter(files, pattern)
results.extend(os.path.join(base, f) for f in goodfiles)
return results
if __name__ == '__main__':
files = recursive_glob(os.cwd(), "*.png")
print(files)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment