MCPcopy Index your code
hub / github.com/python/cpython / walk

Method walk

Lib/pathlib/types.py:343–372  ·  view source on GitHub ↗

Walk the directory tree from this directory, similar to os.walk().

(self, top_down=True, on_error=None, follow_symlinks=False)

Source from the content-addressed store, hash-verified

341 return select(self.joinpath(''))
342
343 def walk(self, top_down=True, on_error=None, follow_symlinks=False):
344 """Walk the directory tree from this directory, similar to os.walk()."""
345 paths = [self]
346 while paths:
347 path = paths.pop()
348 if isinstance(path, tuple):
349 yield path
350 continue
351 dirnames = []
352 filenames = []
353 if not top_down:
354 paths.append((path, dirnames, filenames))
355 try:
356 for child in path.iterdir():
357 if child.info.is_dir(follow_symlinks=follow_symlinks):
358 if not top_down:
359 paths.append(child)
360 dirnames.append(child.name)
361 else:
362 filenames.append(child.name)
363 except OSError as error:
364 if on_error is not None:
365 on_error(error)
366 if not top_down:
367 while not isinstance(paths.pop(), tuple):
368 pass
369 continue
370 if top_down:
371 yield path, dirnames, filenames
372 paths += [path.joinpath(d) for d in reversed(dirnames)]
373
374 @abstractmethod
375 def readlink(self):

Callers

nothing calls this directly

Calls 5

popMethod · 0.45
appendMethod · 0.45
iterdirMethod · 0.45
is_dirMethod · 0.45
joinpathMethod · 0.45

Tested by

no test coverage detected