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: Add flags or function in pathlib.Path
Type: Stage:
Components: Library (Lib) Versions: Python 3.10
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: barneygale, tetelevm
Priority: normal Keywords:

Created on 2021-05-20 20:56 by tetelevm, last changed 2022-04-11 14:59 by admin.

Messages (2)
msg394064 - (view) Author: Mikhail (tetelevm) * Date: 2021-05-20 20:56
Hello! This is a very useful feature when a Path-object gets a list (or generator, as it is now) of files/dirs in self.dir, I think. Right now this is the .iterdir() function, but sometimes you only need `dirs` of that path (for example, I really needed the function when I was working with images for classification), and at the moment this is only solved by (path for path in root.iterdir() if path.is_dir()). You could make separate functions for this, but I suggest just adding the only_dirs/only_files(/only_links) flags to .iterdir().
msg394145 - (view) Author: Barney Gale (barneygale) * Date: 2021-05-21 19:22
My view:

I think the existing solution (that you highlight) is sufficiently idiomatic and easy to discover, and doesn't warrant a new argument or function.

However, that may change when `Path` is subclassable, for two reasons:

1. You will be able to subclass `Path` and add your own method, which you may find preferable to a helper function.
2. We _may_ add some sort of file type enum that wraps the constants in `stat`. In that case it might be natural to add a `file_type` argument to `iterdir()`. No promises!
History
Date User Action Args
2022-04-11 14:59:45adminsetgithub: 88364
2021-05-21 19:22:11barneygalesetnosy: + barneygale
messages: + msg394145
2021-05-20 20:56:21tetelevmcreate