Skip to content

Commit 192b2ea

Browse files
committed
⚡️ Refactor fs_walk function to improve readability and performance
1 parent 7b580a5 commit 192b2ea

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

zcollection/fs_utils.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,12 @@ def fs_walk(
9090
yield '', [], []
9191
return
9292

93-
for info in listing:
93+
for is_dir, name in ((info['type'] == 'directory', info['name'])
94+
for info in listing):
9495
# each info name must be at least [path]/part , but here
9596
# we check also for names like [path]/part/
96-
pathname: str = info['name'].rstrip(SEPARATOR)
97-
name: str = pathname.rsplit(SEPARATOR, 1)[-1]
98-
if info['type'] == 'directory' and pathname != path:
99-
# do not include "self" path
100-
dirs.append(pathname)
101-
else:
102-
files.append(name)
97+
dirs.append(name) if is_dir else files.append(
98+
name.rsplit(SEPARATOR, 1)[-1])
10399

104100
def sort_sequence(sequence: list[str]) -> list[str]:
105101
"""Sort the sequence if the user wishes."""

0 commit comments

Comments
 (0)