VOOZH about

URL: https://www.geeksforgeeks.org/python/python-os-path-isdir-method/

⇱ os.path.isdir() method | Python - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

os.path.isdir() method | Python

Last Updated : 21 Apr, 2026

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.


Output
False

Explanation: os.path.isdir(path) checks if path refers to an existing directory.

Syntax

os.path.isdir(path)

  • Parameters:path - A string or path-like object representing a file system path.
  • Return: Returns True if the path is an existing directory, otherwise False.

Examples

Example 1: This example checks whether a file path refers to a directory.


Output
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.


Output
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.


Output
True
True

Explanation: os.path.isdir("linkdir") returns True because the symbolic link points to a directory.

Comment