Tu's in die Cloud, höhöhö....
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dirs.py 1016B

1234567891011121314151617181920212223242526272829
  1. import os
  2. def list_files_absolute(start_dir, extensions=None):
  3. start_dir = os.path.expanduser(start_dir)
  4. return _list_files(start_dir, start_dir, extensions)
  5. def list_files_relative(start_dir, extensions=None):
  6. start_dir = os.path.expanduser(start_dir)
  7. return _list_files(start_dir, start_dir, extensions, relative=True)
  8. def _list_files(start_dir, cur_dir, extensions=None, relative=False):
  9. paths = []
  10. with os.scandir(cur_dir) as scanner:
  11. for entry in scanner:
  12. if entry.is_dir():
  13. paths += _list_files(start_dir, entry.path, extensions, relative)
  14. elif (
  15. extensions is not None
  16. and any([entry.name.endswith("." + ext) for ext in extensions])
  17. ) or extensions is None:
  18. if relative:
  19. name = os.path.relpath(entry.path, start=start_dir)
  20. else:
  21. name = entry.path
  22. paths.append((name, entry.stat()))
  23. return paths