Python 3.4+pathlibterm
pathlib.WindowsPath
concrete paths
A concrete path with I/O on Windows; what Path() returns there.
Syntax
pathlib.WindowsPath(*segments)
WindowsPath cannot be instantiated on Linux or macOS — you get UnsupportedOperation (NotImplementedError before 3.13); to parse Windows-style paths anywhere, use PureWindowsPath, which never touches the disk. Comparison and hashing are case-insensitive here: PureWindowsPath('A.TXT') == PureWindowsPath('a.txt') is True, whereas POSIX paths treat those as two different files. Forward slashes are accepted on input, but the path prints back with backslashes.
Examples
import pathlib
print(issubclass(pathlib.WindowsPath, pathlib.PureWindowsPath)) # → True
print(hasattr(pathlib.WindowsPath, 'exists'), hasattr(pathlib.PureWindowsPath, 'exists')) # → True False
print(pathlib.PureWindowsPath('C:/Users/ivan/note.txt').name) # → note.txt
print(pathlib.PureWindowsPath('C:/Users/ivan/note.txt').parent) # → C:\Users\ivan
print(type(pathlib.Path('.')).__name__) # → WindowsPath на Windows, PosixPath на Linux/macOS
See also
Open in the full glossarydocs.python.orgReport an inaccuracy