[Python-ideas] pathlib.Path.walk

Michel Desmoulin desmoulinmichel at gmail.com
Mon Apr 3 04:33:56 EDT 2017


Like os.walk, but from a Path instance.

We have Path.iterdir, but it's not recursive. Which you use either
os.scandir, or os.walk. In any case, you end up doing:

import os
import pathlib

directory = pathlib.Path(get_dir())

# do things with directory

for root, dirs, files os.walk(directory):
    root = Path(root)
    for f in files:
        f = root / f
            # do something with file

Which is not that bad, but you waste a lot of time discovering how to do
that since you look first for something like Path.walk.



More information about the Python-ideas mailing list