This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Ovsyanka
Recipients Ovsyanka
Date 2022-01-02.18:34:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1641148452.74.0.627954460368.issue46227@roundup.psfhosted.org>
In-reply-to
Content
Pathlib is great, yet every time I have to parse a bunch of files, I have to use os.walk and join paths by hand. That's not a lot of code but I feel like pathlib should have higher-level abstractions for all path-related functionality of os. I propose we add a Path.walk method that could look like this:

def walk(self, topdown=True, onerror=None, followlinks=False):
    for root, dirs, files in self._accessor.walk(
        self,
        topdown=topdown,
        onerror=onerror,
        followlinks=followlinks
    ):
        root_path = Path(root)
        yield (
            root_path,
            [root_path._make_child_relpath(dir_) for dir_ in dirs],
            [root_path._make_child_relpath(file) for file in files],
        )


Note: this version does not handle a situation when top does not exist (similar to os.walk that also doesn't handle it and just returns an empty generator)
History
Date User Action Args
2022-01-02 18:34:12Ovsyankasetrecipients: + Ovsyanka
2022-01-02 18:34:12Ovsyankasetmessageid: <1641148452.74.0.627954460368.issue46227@roundup.psfhosted.org>
2022-01-02 18:34:12Ovsyankalinkissue46227 messages
2022-01-02 18:34:12Ovsyankacreate