import fnmatch
import os
def locate(pattern, root=os.curdir):
'''Locate all files matching supplied filename pattern in and below
supplied root directory.
Original version: http://code.activestate.com/recipes/499305/
'''
for path, dirs, files in os.walk(os.path.abspath(root)):
for filename in fnmatch.filter(files, pattern):
yield os.path.join(path, filename)
# let's find all js files in the src sibling directory (recurses!)
for file_path in locate('*.js', '../src'):
print file_path # this should print whole path to the file