Primary
os.scandir() ⚬|Documentation|1st|20260715120818-00-⌔
os — Miscellaneous operating system interfaces — Python 3.14.6 documentation#os.scandir
os.scandir(path='.')Return an iterator of
os.DirEntryobjects corresponding to the entries in the directory given by path. The entries are yielded in arbitrary order, and the special entries'.'and'..'are not included. If a file is removed from or added to the directory after creating the iterator, whether an entry for that file be included is unspecified.Using
scandir()instead oflistdir()can significantly increase the performance of code that also needs file type or file attribute information, becauseos.DirEntryobjects expose this information if the operating system provides it when scanning a directory. Allos.DirEntrymethods may perform a system call, butis_dir()andis_file()usually only require a system call for symbolic links;os.DirEntry.stat()always requires a system call on Unix but only requires one for symbolic links on Windows.path may be a path-like object. If path is of type
bytes(directly or indirectly through thePathLikeinterface), the type of thenameandpathattributes of eachos.DirEntrywill bebytes; in all other circumstances, they will be of typestr.This function can also support specifying a file descriptor; the file descriptor must refer to a directory.
Raises an auditing event
os.scandirwith argumentpath.The
scandir()iterator supports the context manager protocol and has the following method:Printed 2026-07-15.
(echo:: @ ᯤ)
Link to original
Secondary
• • •