Skip to content
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

pathlib: iterfiles() and iterdirs() #63966

Closed
jonashaag mannequin opened this issue Nov 25, 2013 · 8 comments
Closed

pathlib: iterfiles() and iterdirs() #63966

jonashaag mannequin opened this issue Nov 25, 2013 · 8 comments
Labels
expert-pathlib stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@jonashaag
Copy link
Mannequin

jonashaag mannequin commented Nov 25, 2013

BPO 19767
Nosy @tds333, @pitrou, @vstinner, @bitdancer, @jonashaag
Files
  • iterdirs_iterfiles.diff
  • path_subdirs_files.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2013-11-25.10:25:47.482>
    labels = ['type-feature', 'library']
    title = 'pathlib: iterfiles() and iterdirs()'
    updated_at = <Date 2014-11-10.08:53:23.186>
    user = 'https://github.com/jonashaag'

    bugs.python.org fields:

    activity = <Date 2014-11-10.08:53:23.186>
    actor = 'tds333'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2013-11-25.10:25:47.482>
    creator = 'jonash'
    dependencies = []
    files = ['32832', '35210']
    hgrepos = []
    issue_num = 19767
    keywords = ['patch']
    message_count = 6.0
    messages = ['204320', '204322', '204333', '217450', '218240', '230944']
    nosy_count = 5.0
    nosy_names = ['tds333', 'pitrou', 'vstinner', 'r.david.murray', 'jonash']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue19767'
    versions = ['Python 3.5']

    @jonashaag
    Copy link
    Mannequin Author

    jonashaag mannequin commented Nov 25, 2013

    From my personal experience, listing all real files and all subdirectories in a directory is a very common use case.

    Here's a patch that adds the iterfiles() and iterdirs() methods as a shortcut for [f for f in p.iterdir() if f.is_dir/file()] .

    @jonashaag jonashaag mannequin added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Nov 25, 2013
    @vstinner
    Copy link
    Member

    See also issue bpo-11406 which is more generic.

    @bitdancer
    Copy link
    Member

    Beta is out, so this issue must be targeted for 3.5.

    @pitrou
    Copy link
    Member

    pitrou commented Apr 28, 2014

    Having an iterdirs() method next to iterdir() is very confusing.
    We should find something else, so how about files() and subdirs()?

    @pitrou
    Copy link
    Member

    pitrou commented May 10, 2014

    Here is a patch with the proposed API. The API for convenience:

        def files(self, include_symlinks=True):
            """Iterate over the regular files in this directory.
            """
    
        def subdirs(self, include_symlinks=True):
            """Iterate over the subdirectories in this directory.
            """

    @tds333
    Copy link
    Mannequin

    tds333 mannequin commented Nov 10, 2014

    Why not implement this pattern with

    def dirs(pattern)
    and 
    def files(pattern)

    where both are a simple shortcut for
    (p for p in mypath.glob(pattern) if p is_file())
    or is_dir()

    ?

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @barneygale
    Copy link
    Contributor

    I'm -1 on this: [f for f in p.iterdir() if f.is_dir/file()] seems perfectly fine.

    @AlexWaygood
    Copy link
    Member

    I agree with @barneygale, and there's been no activity on this issue in >8 years, signalling there isn't truly much of a need for this.

    @AlexWaygood AlexWaygood closed this as not planned Won't fix, can't repro, duplicate, stale Jan 8, 2023
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    expert-pathlib stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    6 participants