def _list_files(path, suffix=''):
 if os.path.isdir(path):
  incomplete = os.listdir(path)
  complete = [os.path.join(path, entry) for entry in incomplete]
  lists = [_list_files(subpath, suffix) for subpath in complete]
  flattened = []
  for l in lists:
   for elem in l:
    flattened.append(elem)
  return flattened
 else:
  assert os.path.exists(path), ("couldn't find file '%s'" % path)
  if path.endswith(suffix):
   return [path]
  return []

def _list_files ( path , suffix = '' ) : if os . path . isdir ( path ) : incomplete = os . listdir ( path ) complete = [ os . path . join ( path , entry ) for entry in incomplete ] lists = [ _list_files ( subpath , suffix ) for subpath in complete ] flattened = [ ] for l in lists : for elem in l : flattened . append ( elem ) return flattened else : assert os . path . exists ( path ) , ( "couldn't find file '%s'" % path ) if path . endswith ( suffix ) : return [ path ] return [ ]
lists all files below the given folder that match the pattern .