Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Lib/pathlib/_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,8 @@ def walk(self, top_down=True, on_error=None, follow_symlinks=False):
with scandir_obj as scandir_it:
dirnames = []
filenames = []
if not top_down:
paths.append((path, dirnames, filenames))
for entry in scandir_it:
try:
is_dir = entry.is_dir(follow_symlinks=follow_symlinks)
Expand All @@ -828,16 +830,15 @@ def walk(self, top_down=True, on_error=None, follow_symlinks=False):
is_dir = False

if is_dir:
if not top_down:
paths.append(path._make_child_entry(entry))
dirnames.append(entry.name)
else:
filenames.append(entry.name)

if top_down:
yield path, dirnames, filenames
else:
paths.append((path, dirnames, filenames))

paths += [path._make_child_relpath(d) for d in reversed(dirnames)]
paths += [path._make_child_relpath(d) for d in reversed(dirnames)]

def absolute(self):
"""Return an absolute version of this path
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Speed up :meth:`pathlib.Path.walk` by using :attr:`os.DirEntry.path` where
possible.