os.path.isdir() method - Python Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report os.path.isdir() method in Python checks whether the specified path is a directory or not. This method follows the symbolic link, which means if the specified path is a symbolic link pointing to an existing directory then the method will return True.Example: Using os.path.isdir() methodThis code demonstrates how to check whether a given path refers to a directory using the os.path.isdir() function in Python. It checks two paths: one for a file and another for a directory. Python import os.path path = '/home/User/Documents/file.txt' isdir = os.path.isdir(path) print(isdir) path = '/home/User/Documents/' isdir = os.path.isdir(path) print(isdir) OutputFalse TrueExplanation: This code checks whether the specified paths refer to directories using the os.path.isdir() function. The first check (/home/User/Documents/file.txt) is for a file, so it returns False because the path is not a directory. The second check (/home/User/Documents/) is for a directory, so it returns True because the path points to an existing directory. Syntaxos.path.isdir(path) Parameter: A path-like object representing a file system path. Return Type: This method returns a Boolean value of class bool. This method returns True if the specified path is an existing directory, otherwise returns False.Note: isdir() stands for "is directory", which justifies its task for checking if the given path is a directory.Using a symbolic linkThis code demonstrates how to create a directory and a symbolic link in Python, and then checks whether those paths refer to directories using the os.path.isdir() function. Python import os.path os.mkdir("GeeksForGeeks") os.symlink("GeeksForGeeks", "/home/User/Desktop/gfg") print(os.path.isdir("GeeksForGeeks")) print(os.path.isdir("/home/User/Desktop/gfg")) OutputTrue TrueExplanation: This code creates a directory "GeeksForGeeks" using os.mkdir() and a symbolic link pointing to it using os.symlink(). It then checks if both the directory and the symbolic link are valid directories using os.path.isdir(). The first check returns True for the "GeeksForGeeks" directory, and the second check returns True for the symbolic link, as it points to an existing directory. Comment More infoAdvertise with us Next Article os.path.isdir() method - Python I ihritik Follow Improve Article Tags : Python python-os-module Python OS-path-module Practice Tags : python Similar Reads Python | os.path.commonpath() method OS module in Python provides functions for interacting with the operating system. OS comes under Pythonâs standard utility modules. This module provides a portable way of using operating system dependent functionality. os.path module is submodule of OS module in Python used for common path name mani 2 min read Python | os.path.commonprefix() method OS module in Python provides functions for interacting with the operating system. OS comes under Pythonâs standard utility modules. This module provides a portable way of using operating system dependent functionality. os.path module is submodule of OS module in Python used for common path name mani 2 min read Python | os.path.dirname() method OS module in Python provides functions for interacting with the operating system. OS comes under Pythonâs standard utility modules. This module provides a portable way of using operating system dependent functionality. os.path module is sub module of OS module in Python used for common path name man 2 min read os.path.exists() method-Python os.path.exists() method in Python check whether a specified path exists or not. This method can be also used to check whether the given path refers to an open file descriptor or not. Example:Pythonimport os print(os.path.exists('/home/User/Desktop/file.txt')) print(os.path.exists('/home/User/Desktop 2 min read Python | os.path.lexists() method OS module in Python provides functions for interacting with the operating system. OS comes under Pythonâs standard utility modules. This module provides a portable way of using operating system dependent functionality. os.path module is sub module of OS module in python used for common path name man 2 min read Python | os.path.expanduser() method OS module in Python provides functions for interacting with the operating system. OS comes under Pythonâs standard utility modules. This module provides a portable way of using operating system dependent functionality. os.path module is sub module of OS module in Python used for common pathname mani 4 min read Python | os.path.expandvars() method OS module in Python provides functions for interacting with the operating system. OS comes under Pythonâs standard utility modules. This module provides a portable way of using operating system dependent functionality. os.path the module is a submodule of OS module in Python used for common pathname 3 min read Python | os.path.getatime() method OS module in Python provides functions for interacting with the operating system. OS comes under Pythonâs standard utility modules. This module provides a portable way of using operating system dependent functionality. os.path module is sub module of OS module in Python used for common path name man 2 min read Python | os.path.getmtime() method OS module in Python provides functions for interacting with the operating system. OS comes under Pythonâs standard utility modules. This module provides a portable way of using operating system dependent functionality. os.path module is sub module of OS module in Python used for common path name man 2 min read Python | os.path.getctime() method OS module in Python provides functions for interacting with the operating system. OS comes under Pythonâs standard utility modules. This module provides a portable way of using operating system dependent functionality. os.path module is sub module of OS module in Python used for common path name man 2 min read Like