stat.S_ISDIR()
stat.S_ISDIR() is a Python function in the Stat Module category. Returns True if the file mode indicates a directory. The syntax is stat.S_ISDIR(mode). Parameters: mode — st_mode from os.stat(). Returns: Boolean. A typical example: import stat
import os
mode = os.stat("file.txt").st_mode
stat.S_ISDIR(mode) # False (it's a file)
stat.S_ISREG(mode) # True (regular file). A close sibling is stat.S_ISREG(), which returns True if the file mode indicates a regular file. A close sibling is stat.S_ISLNK(), which returns True if the file mode indicates a symbolic link. A close sibling is stat.S_ISFIFO(), which returns True if the file mode indicates a FIFO (named pipe). A close sibling is stat.S_ISSOCK(), which returns True if the file mode indicates a Unix socket. More about this category: File stat constants — S_ISDIR, S_ISREG, S_IMODE, S_IFMT. Related Stat Module entries: stat.S_ISREG(), stat.S_ISLNK(), stat.S_ISFIFO(), stat.S_ISSOCK(), stat.S_IMODE(), stat.S_IFMT().