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
|
@ -639,13 +639,23 @@ class PathBase(PurePathBase):
|
|||
with self.open(mode='w', encoding=encoding, errors=errors, newline=newline) as f:
|
||||
return f.write(data)
|
||||
|
||||
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.
|
||||
"""
|
||||
raise UnsupportedOperation(self._unsupported_msg('scandir()'))
|
||||
|
||||
def iterdir(self):
|
||||
"""Yield path objects of the directory contents.
|
||||
|
||||
The children are yielded in arbitrary order, and the
|
||||
special entries '.' and '..' are not included.
|
||||
"""
|
||||
raise UnsupportedOperation(self._unsupported_msg('iterdir()'))
|
||||
with self.scandir() as entries:
|
||||
names = [entry.name for entry in entries]
|
||||
return map(self.joinpath, names)
|
||||
|
||||
def _glob_selector(self, parts, case_sensitive, recurse_symlinks):
|
||||
if case_sensitive is None:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue