OS Path module in Python Last Updated : 23 Jan, 2024 Comments Improve Suggest changes Like Article Like Report 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 objects as their parameters. The result is an object of the same type if a path or file name is returned. As there are different versions of the operating system there are several versions of this module in the standard library. In this article, we will start working with Paths in the Python OS Module. Working with Paths in Python OS ModuleBelow are some OS Path functions by which we can do Path Manipulation in the Python OS Module: os.path.basename(path)os.path.dirname(path) os.path.isabs(path)os.path.isdir(path)os.path.isfile(path)os.path.normcase(path)os.path.normpath(path)os.path.basename(path)os.path.basename(path) is used to return the basename of the file. This function returns the file name from the path given. Python3 # basename function import os out = os.path.basename("/baz/foo") print(out) Outputfooos.path.dirname(path)os.path.dirname(path) is used to return the directory name from the path given. This function returns the name from the path except the path name. Python3 # dirname function import os out = os.path.dirname("/baz/foo") print(out) Output/bazos.path.isabs(path)os.path.isabs(path) specifies whether the path is absolute or not. In Unix system absolute path means path begins with the slash('/') and in Windows that it begins with a (back)slash after chopping off a potential drive letter. Python # isabs function import os out = os.path.isabs("/baz/foo") print(out) OutputTrueos.path.isdir(path)os.path.isdir(path) function specifies whether the path is existing directory or not. Python # isdir function import os out = os.path.isdir("C:\\Users") print(out) Output: Trueos.path.isfile(path)os.path.isfile(path) function specifies whether the path is existing file or not. Python # isfile function import os out = os.path.isfile("C:\\Users\foo.csv") print(out) Output: Trueos.path.normcase(path)os.path.normcase(path) function normalizes the case of the pathname specified. In Unix and Mac OS X system it returns the pathname as it is . But in Windows it converts the path to lowercase and forward slashes to backslashes. Python # normcase function in windows import os out = os.path.normcase("/BAz") print(out) Output: '\\baz'os.path.normpath(path)os.path.normpath(path) function normalizes the path names by collapsing redundant separators and up-level references so that A//B, A/B/, A/./B and A/foo/../B all become A/B. On Windows, it converts forward slashes to backward slashes . Python # normpath function in Unix import os out = os.path.normpath("foo/./bar") print(out) Output: 'foo/bar' Comment More infoAdvertise with us Next Article os.path.abspath() method - Python S Surya Priy Follow Improve Article Tags : Python Python-Library python-modules 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 Python | os.path.exists() method os.path.exists() method in Python is used to check whether the 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. os.path.exists() Syntax in PythonSyntax: os.path.exists(path) Parameter: path: A path-like object repres 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