os.path.exists() method-Python Last Updated : 01 Jul, 2025 Comments Improve Suggest changes Like Article Like Report 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: Python import os print(os.path.exists('/home/User/Desktop/file.txt')) print(os.path.exists('/home/User/Desktop/')) print(os.path.exists('nonexistent.txt')) OutputTrueTrueFalseExplanation:The first two statements return True assuming the file and directory exist at the given paths.The third returns False because 'nonexistent.txt' does not exist in the current directory.Syntax of os.path.exits()os.path.exists(path)Parameter: path is a path-like object representing a file system location. This can be a str, bytes or object implementing __fspath__().Return Type: bool returns True if the path exists, False otherwise.ExamplesExample 1: Using with relative paths Python import os print(os.path.exists('example.txt')) print(os.path.exists('./no_such_dir')) OutputTrueFalseExplanation:'example.txt' is checked relative to the current working directory. If it exists there, it returns True.'./no_such_dir' refers to a subdirectory that does not exist, so it returns False.Example 2: Checking an empty path Python import os path = '' print(os.path.exists(path)) OutputFalseExplanation: An empty string is not a valid path, so os.path.exists() returns False.Related articlesos.path.isfile() os.path.isdir()os module Comment More infoAdvertise with us Next Article Python | os.path.lexists() method I ihritik Follow Improve Article Tags : Python python-os-module Practice Tags : python Similar Reads OS Path module in Python OS Path module contains some useful functions on pathnames. The path parameters are either strings or bytes. These functions here are used for different purposes such as for merging, normalizing, and retrieving path names in Python. All of these functions accept either only bytes or only string obje 2 min read os.path.abspath() method - Python The os.path.abspath() method in Python's os module is used to get the full (absolute) path of a file or folder. It's useful when you're working with relative paths but need to know the exact location on your system. If you pass a relative path, it converts it to an absolute one and if the path is al 2 min read Python | os.path.basename() 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 4 min read 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 Like