def _depth_limited_walk(top, max_depth=None):
 for (root, dirs, files) in os.walk(top):
  if (max_depth is not None):
   rel_depth = (root.count(os.sep) - top.count(os.sep))
   if (rel_depth >= max_depth):
    del dirs[:]
  (yield (str(root), list(dirs), list(files)))

def _depth_limited_walk ( top , max_depth = None ) : for ( root , dirs , files ) in os . walk ( top ) : if ( max_depth is not None ) : rel_depth = ( root . count ( os . sep ) - top . count ( os . sep ) ) if ( rel_depth >= max_depth ) : del dirs [ : ] ( yield ( str ( root ) , list ( dirs ) , list ( files ) ) )
walk the directory tree under root up till reaching max_depth .