(path='.', depth=None)
recursively walk directory to specified depth
    :param path: (str) the base path to start walking from
    :param depth: (None or int) max. recursive depth, None = no limit
    :yields: (str) filename, including path
recursively walk directory to specified depth
    :param path: (str) the base path to start walking from
    :param depth: (None or int) max. recursive depth, None = no limit
    :yields: (str) filename, including path
recursively walk directory to specified depth : param path : ( str ) the base path to start walking from : param depth : ( None or int ) max . recursive depth None = no limit : yields : ( str ) filename including path
def walk(path='.', depth=None):
  """
    recursively walk directory to specified depth
    :param path: (str) the base path to start walking from
    :param depth: (None or int) max. recursive depth, None = no limit
    :yields: (str) filename, including path
    """
  if depth and depth == 1:
    for filename in listdir(path):
      yield filename
  else:
    top_pathlen = len(path) + len(os.path.sep)
    for dirpath, dirnames, filenames in os.walk(path):
      dirlevel = dirpath[top_pathlen:].count(os.path.sep)
      if depth and dirlevel >= depth:
        dirnames[:] = []
      else:
        for filename in filenames:
          yield os.path.join(dirpath, filename)
def walk ( path = '.' , depth = None ) : if depth and depth == 1 : for filename in listdir ( path ) : yield filename else : top_pathlen = len ( path ) + len ( os . path . sep ) for dirpath , dirnames , filenames in os . walk ( path ) : dirlevel = dirpath [ top_pathlen : ] . count ( os . path . sep ) if depth and dirlevel >= depth : dirnames [ : ] = [ ] else : for filename in filenames : yield os . path . join ( dirpath , filename )