iterdir
iterdir is a method of the pathlib.Path class in Python that returns an iterator over the entries contained in a directory. Each item yielded by the iterator is a Path object representing a file, subdirectory, or symbolic link within the directory. The method is non-recursive, meaning it only lists the immediate contents of the specified directory.
The iterator is lazy and typically backed by an efficient system call, often using the operating system’s
Common considerations include potential exceptions: a FileNotFoundError occurs if the path does not exist, a NotADirectoryError
Typical usage is straightforward: for child in Path("/path/to/dir").iterdir(): print(child) or filter with conditions such as if