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.

classification
Title: pathlib: iterfiles() and iterdirs()
Type: enhancement Stage: patch review
Components: Library (Lib) Versions: Python 3.5
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: jonash, pitrou, r.david.murray, tds333, vstinner
Priority: normal Keywords: patch

Created on 2013-11-25 10:25 by jonash, last changed 2022-04-11 14:57 by admin.

Files
File name Uploaded Description Edit
iterdirs_iterfiles.diff jonash, 2013-11-25 10:25 review
path_subdirs_files.patch pitrou, 2014-05-10 22:55 review
Messages (6)
msg204320 - (view) Author: Jonas H. (jonash) * Date: 2013-11-25 10:25
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()]` .
msg204322 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2013-11-25 10:30
See also issue #11406 which is more generic.
msg204333 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-11-25 12:39
Beta is out, so this issue must be targeted for 3.5.
msg217450 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2014-04-28 23:46
Having an `iterdirs()` method next to `iterdir()` is very confusing.
We should find something else, so how about `files()` and `subdirs()`?
msg218240 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2014-05-10 22:55
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.
        """
msg230944 - (view) Author: Wolfgang Langner (tds333) * Date: 2014-11-10 08:53
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()

?
History
Date User Action Args
2022-04-11 14:57:54adminsetgithub: 63966
2014-11-10 08:53:23tds333setnosy: + tds333
messages: + msg230944
2014-05-10 22:55:50pitrousetstage: patch review
2014-05-10 22:55:26pitrousetfiles: + path_subdirs_files.patch

messages: + msg218240
2014-04-28 23:46:40pitrousetnosy: + pitrou
messages: + msg217450
2013-11-25 12:39:03r.david.murraysetnosy: + r.david.murray

messages: + msg204333
versions: + Python 3.5, - Python 3.4
2013-11-25 10:30:51vstinnersetnosy: + vstinner
messages: + msg204322
2013-11-25 10:25:47jonashcreate