code: def find(file_pattern, top_dir, max_depth=None, path_pattern=None):
      
      if max_depth:
          base_depth = os.path.dirname(top_dir).count(os.path.sep)
          max_depth += base_depth
  
      for path, dirlist, filelist in os.walk(top_dir):
          if max_depth and path.count(os.path.sep) >= max_depth:
              del dirlist[:]
  
          if path_pattern and not fnmatch.fnmatch(path, path_pattern):
              continue
  
          for name in fnmatch.filter(filelist, file_pattern):
              yield os.path.join(path, name)
docs: Generator function to find files recursively.
      Usage::
  
          for filename in find("*.properties", "/var/log/foobar"):
              print filename