Python Glossary Русский

Python 3.5+osterm

os.DirEntry

os — file system

The item type yielded by os.scandir(): name, path, and cached is_file()/is_dir()/stat().

Syntax

entry.name  # os.DirEntry

The object is short-lived: it captures data as of reading the directory and does not track changes. is_dir() and is_file() follow symlinks by default; is_symlink() does not. entry.path is built from the scandir argument, so a relative argument gives a relative path. It implements os.PathLike and works with open().

Examples

import os
d = os.path.dirname(os.__file__)
it = os.scandir(d)
print(isinstance(next(it), os.DirEntry))   # → True
it.close()

See also

Open in the full glossarydocs.python.orgReport an inaccuracy