Created
April 10, 2012 07:10
-
-
Save bcse/2348948 to your computer and use it in GitHub Desktop.
Recursively list files
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, 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