ID EN
OS

scandir

Python 3.11

Return an iterator of os.DirEntry objects 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.

Syntax

PYTHON
os.scandir(path='.')

Examples

Example 1
PYTHON
with os.scandir(path) as it:
    for entry in it:
        if not entry.name.startswith('.') and entry.is_file():
            print(entry.name)

See Also

os.DirEntry scandir() listdir() os.DirEntry os.DirEntry is_dir() is_file() os.DirEntry.stat()