code: def collect_files(path, extension):
      
  
      # We should only call this on an actual directory; callers should do the
      # validation.
      assert os.path.isdir(path)
      out = []
      # glob would be faster (see PEP471) but python glob doesn't do **/*
      for root, _, files in os.walk(path):
          out += [os.path.join(root, f) for f in files if f.endswith(extension)]
      return out
docs: Collect all the files with extension in a directory tree.