Skip to content

Instantly share code, notes, and snippets.

@bcse
Created April 10, 2012 07:10
Show Gist options
  • Save bcse/2348948 to your computer and use it in GitHub Desktop.
Save bcse/2348948 to your computer and use it in GitHub Desktop.
Recursively list files
import os, fnmatch
def locate(pattern, root=os.curdir):
'''Locate all files matching supplied filename pattern in and below
supplied root directory.'''
for path, dirs, files in os.walk(os.path.abspath(root)):
for filename in fnmatch.filter(files, pattern):
yield os.path.join(path, filename)
if __name__ == '__main__':
for s in locate('*.png'):
print s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment