![]() |
VOOZH | about |
os.path.isdir() method used to check whether a given file system path refers to an existing directory. It returns True if the path points to a directory; otherwise, it returns False. This method also follows symbolic links, meaning a symbolic link pointing to a directory is treated as a directory.
This example checks whether a given path exists and is a directory.
False
Explanation: os.path.isdir(path) checks if path refers to an existing directory.
os.path.isdir(path)
Example 1: This example checks whether a file path refers to a directory.
False
Explanation: os.path.isdir(path) returns False because path points to a file, not a directory.
Example 2: This example verifies whether a directory path exists and is a directory.
False
Explanation: output is False because "Documents" refers to a directory that does not exist in the script's current working directory.
Example 3: This example checks whether a symbolic link pointing to a directory is treated as a directory.
True True
Explanation: os.path.isdir("linkdir") returns True because the symbolic link points to a directory.