Jun-18-2020, 04:12 PM
Why do you use your own complicated implementation (which could not handle WindowPaths) instead of using
os.walk
?os.walk
example as generatorimport os from pathlib import Path def walk(path, maxdepth=None, sort_key=None, with_files=True, with_dirs=True): for depth, (root, dirs, files) in enumerate(os.walk(path)): if maxdepth is not None and depth > maxdepth: return if with_dirs: for directory in sorted(dirs, key=sort_key): yield Path(root, directory) if with_files: for file in sorted(files, key=sort_key): yield Path(root, file)If you need compatibility to Python 2.7 (hopefully not), omit pathlib and use os.path.join.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!