Issue 19767: pathlib: iterfiles() and iterdirs() (original) (raw)

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:54 admin set github: 63966
2014-11-10 08:53:23 tds333 set nosy: + tds333messages: +
2014-05-10 22:55:50 pitrou set stage: patch review
2014-05-10 22:55:26 pitrou set files: + path_subdirs_files.patchmessages: +
2014-04-28 23:46:40 pitrou set nosy: + pitroumessages: +
2013-11-25 12:39:03 r.david.murray set nosy: + r.david.murraymessages: + versions: + Python 3.5, - Python 3.4
2013-11-25 10:30:51 vstinner set nosy: + vstinnermessages: +
2013-11-25 10:25:47 jonash create