Skip to content

bpo-36602: Allow pathlib.Path.iterdir to list recursively #12785

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 31 commits into from

Conversation

EpicWink
Copy link
Contributor

@EpicWink EpicWink commented Apr 11, 2019

Currently, pathlib.Path.iterdir only lists contents of the instance directory. This enhancement allows iterdir to recurse into subdirectories.

The issue references two decisions to be made. I have initially chosen to not yield the contained directories themselves, and I have initially chosen to not resolve paths before checking if they're a directory to be recursed into. Don't hesitate to give criticism on these choices.

In addition, I've decided to make recursive a keyword-only argument, as path.iterdir(True) didn't seem very readable.

https://bugs.python.org/issue36602

@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA).

Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA (this might be simply due to a missing "GitHub Name" entry in your b.p.o account settings). This is necessary for legal reasons before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

You can check yourself to see if the CLA has been received.

Thanks again for your contribution, we look forward to reviewing it!

@EpicWink EpicWink force-pushed the feat/pathlib-iterdir branch 3 times, most recently from a40cf6b to 55b10f9 Compare April 11, 2019 11:37
@EpicWink EpicWink force-pushed the feat/pathlib-iterdir branch from 55b10f9 to 8125ca9 Compare April 12, 2019 03:52
@brettcannon brettcannon added the type-feature A feature request or enhancement label Apr 17, 2019
@bedevere-bot
Copy link

Thanks for making the requested changes!

: please review the changes made to this pull request.

@EpicWink
Copy link
Contributor Author

EpicWink commented May 9, 2019

#13153 has implemented the pathlib.Path API for zip-files. I would suspect an new request would be needed for updating zipfile with recursive directory listing as well

@EpicWink EpicWink force-pushed the feat/pathlib-iterdir branch from f462f48 to 95d4c49 Compare June 5, 2019 23:41
@EpicWink EpicWink force-pushed the feat/pathlib-iterdir branch from 1f580aa to 4bb3b29 Compare October 15, 2019 04:48
@EpicWink EpicWink requested a review from pganssle October 21, 2019 11:41
@EpicWink
Copy link
Contributor Author

EpicWink commented Aug 3, 2022

The introduction of pathlib.Path.walk, the existance of path.rglob("**"), and the simplicity of writing a helper function all contribute to my thinking this feature is not necessary. Feel free to close #80783.

PS: helper function:

def iterdir_recursive(path: pathlib.Path) -> typing.Generator[pathlib.Path, None, None]:
    for child in path.iterdir():
        if child.is_dir():
            yield from iterdir_recursive(child)
        else:
            yield child

@EpicWink EpicWink closed this Aug 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants