mirror of
https://github.com/python/cpython.git
synced 2025-08-09 19:38:42 +00:00
GH-125413: Add pathlib.Path.scandir()
method (#126060)
Add `pathlib.Path.scandir()` as a trivial wrapper of `os.scandir()`. This will be used to implement several `PathBase` methods more efficiently, including methods that provide `Path.copy()`.
This commit is contained in:
parent
d0abd0b826
commit
260843df1b
6 changed files with 114 additions and 11 deletions
|
@ -615,6 +615,14 @@ class Path(PathBase, PurePath):
|
|||
path_str = path_str[:-1]
|
||||
yield path_str
|
||||
|
||||
def scandir(self):
|
||||
"""Yield os.DirEntry objects of the directory contents.
|
||||
|
||||
The children are yielded in arbitrary order, and the
|
||||
special entries '.' and '..' are not included.
|
||||
"""
|
||||
return os.scandir(self)
|
||||
|
||||
def iterdir(self):
|
||||
"""Yield path objects of the directory contents.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue