# HG changeset patch # User Franz Glasner # Date 1736167089 -3600 # Node ID c7df81fb84b78dc9e95ca2a96f323800312b8c4a # Parent 3505406ef9f364c4b58b2312da5487708b30a3bb Merge dirs and nondirs into one list that is yielded from "util.walk()" diff -r 3505406ef9f3 -r c7df81fb84b7 cutils/util/walk.py --- a/cutils/util/walk.py Sat Jan 04 15:41:00 2025 +0100 +++ b/cutils/util/walk.py Mon Jan 06 13:38:09 2025 +0100 @@ -130,8 +130,11 @@ - the `root` is never part of the returned data - the returned directory in "top" is not a string form but a list of individual path segments - - all other yielded lists contain WalkDirEntry elements instead of - strings + - there is only one yields list + + * contains :class:`WalkDirEntry` + * sorted by its fsname + - recurse into sub-directories first ("topdown=False") - sort consistently all yielded lists by the filesystem encoding @@ -154,7 +157,7 @@ else: path = root - dirs, nondirs, walk_dirs = [], [], [] + fsobjects, walk_dirs = [], [] scandir_cm = scandir(path) if not hasattr(scandir_cm, "close"): @@ -165,10 +168,7 @@ entry = WalkDirEntry.from_direntry(next(scandir_it)) except StopIteration: break - if entry.is_dir: - dirs.append(entry) - else: - nondirs.append(entry) + fsobjects.append(entry) # # Always bottom-up: recurse into sub-directories, but exclude # symlinks to directories if follow_symlinks is False @@ -183,14 +183,13 @@ # Sort by low-level filesystem encoding walk_dirs.sort(key=WalkDirEntry.sort_key) - dirs.sort(key=WalkDirEntry.sort_key) - nondirs.sort(key=WalkDirEntry.sort_key) + fsobjects.sort(key=WalkDirEntry.sort_key) # Recurse into sub-directories for wd in walk_dirs: yield from _walk(root, top + (wd.name,), follow_symlinks) # Yield after recursion if going bottom up - yield top, dirs, nondirs + yield top, fsobjects else: