ospathcommonpathusrlibusrlocalbin
os.path.commonpath is a function in Python's standard library that returns the longest common subpath for a sequence of filesystem paths. It operates according to the path semantics of the underlying operating system (posix on Unix-like systems, nt on Windows). The function takes a single argument, paths, which is an iterable of path-like objects (strings or bytes that can be converted with os.fspath). It returns a string representing the common path prefix shared by all input paths after normalization.
If paths is empty or if the provided paths do not share any common path, a ValueError
- os.path.commonpath(['/a/b/c','/a/b/d','/a/b']) yields '/a/b'.
- os.path.commonpath(['C:\\Users\\Public','C:\\Users\\Admin']) yields 'C:\\Users'.
- os.path.commonpath(['/usr/local/bin','/usr/bin/python']) yields '/usr'.
commonpath is distinct from os.path.commonprefix, which returns the longest shared string prefix without considering path boundaries
os.path.commonprefix, os.path.abspath, os.path.normpath, os.path.normcase.