On this page
pathlib.WindowsPath
Prev: pathlib.UnsupportedOperation | Up: pathlib
Rel: pathlib.Path, pathlib.PosixPath, pathlib.PurePath, pathlib.PurePosixPath
Ref: docs.python.org — pathlib.WindowsPath
Tags: #public #python3 #stdlib #pathlib
Import
import pathlib
from pathlib import WindowsPath
Signature & Overview
pathlib.WindowsPath(*args, **kwargs)
Path subclass for Windows systems.
Methods & Attributes
WindowsPath.absolute(self)— Return an absolute version of this path No normalization or symlink resolution is performed.WindowsPath.anchor(...)— The concatenation of the drive and root, or ''.WindowsPath.as_posix(self)— Return the string representation of the path with forward (/) slashes.WindowsPath.as_uri(self)— Return the path as a URI.WindowsPath.chmod(self, mode, *, follow_symlinks=True)— Change the permissions of the path, like os.chmod().WindowsPath.copy(self, target, **kwargs)— Recursively copy this file or directory tree to the given destination.WindowsPath.copy_into(self, target_dir, **kwargs)— Copy this file or directory tree into the given existing directory.WindowsPath.cwd()— Return a new path pointing to the current working directory.WindowsPath.drive(...)— The drive prefix (letter or UNC path), if any.WindowsPath.exists(self, *, follow_symlinks=True)— Whether this path exists.WindowsPath.expanduser(self)— Return a new path with expanded ~ and ~user constructs (as returned by os.path.expanduser)WindowsPath.from_uri(uri)— Return a new path from the given 'file' URI.WindowsPath.full_match(self, pattern, *, case_sensitive=None)— Return True if this path matches the given glob-style pattern. The pattern is matched against the entire path.WindowsPath.glob(self, pattern, *, case_sensitive=None, recurse_symlinks=False)— Iterate over this subtree and yield all existing files (of any kind, including directories) matching the given relative pattern.WindowsPath.group(self, *, follow_symlinks=True)— Return the group name of the file gid.WindowsPath.hardlink_to(self, target)— Make this path a hard link pointing to the same file as target.WindowsPath.home()— Return a new path pointing to expanduser('~').WindowsPath.info(...)— A PathInfo object that exposes the file type and other file attributes of this path.WindowsPath.is_absolute(self)— True if the path is absolute (has both a root and, if applicable, a drive).WindowsPath.is_block_device(self)— Whether this path is a block device.WindowsPath.is_char_device(self)— Whether this path is a character device.WindowsPath.is_dir(self, *, follow_symlinks=True)— Whether this path is a directory.WindowsPath.is_fifo(self)— Whether this path is a FIFO.WindowsPath.is_file(self, *, follow_symlinks=True)— Whether this path is a regular file (also True for symlinks pointing to regular files).WindowsPath.is_junction(self)— Whether this path is a junction.WindowsPath.is_mount(self)— Check if this path is a mount pointWindowsPath.is_relative_to(self, other)— Return True if the path is relative to another path or False.WindowsPath.is_reserved(self)— Return True if the path contains one of the special names reserved by the system, if any.WindowsPath.is_socket(self)— Whether this path is a socket.WindowsPath.is_symlink(self)— Whether this path is a symbolic link.WindowsPath.iterdir(self)— Yield path objects of the directory contents.WindowsPath.joinpath(self, *pathsegments)— Combine this path with one or several arguments, and return a new path representing either a subpath (if all arguments are relative paths) or a totally different path (if one of the arguments isWindowsPath.lchmod(self, mode)— Like chmod(), except if the path points to a symlink, the symlink's permissions are changed, rather than its target's.WindowsPath.lstat(self)— Like stat(), except if the path points to a symlink, the symlink's status information is returned, rather than its target's.WindowsPath.match(self, path_pattern, *, case_sensitive=None)— Return True if this path matches the given pattern. If the pattern is relative, matching is done from the right; otherwise, the entire path is matched. The recursive wildcard '**' is not supported by thisWindowsPath.mkdir(self, mode=511, parents=False, exist_ok=False)— Create a new directory at this given path.WindowsPath.move(self, target)— Recursively move this file or directory tree to the given destination.WindowsPath.move_into(self, target_dir)— Move this file or directory tree into the given existing directory.WindowsPath.name(...)— The final path component, if any.WindowsPath.open(self, mode='r', buffering=-1, encoding=None, errors=None, newline=None)— Open the file pointed to by this path and return a file object, as the built-in open() function does.
Usage
import os
from pathlib import WindowsPath
if os.name == "nt":
p = WindowsPath(r"C:\Windows\System32")
assert p.drive == "C:" and p.is_absolute()
Gotchas
- Windows-only concrete class: Instantiating
WindowsPathon macOS or Linux raisesUnsupportedOperation. - Prefer
PathorPureWindowsPath: UsePathfor portable filesystem operations andPureWindowsPathfor parsing Windows paths on Unix.
REPL Inspect
from pathlib import WindowsPath
help(WindowsPath)
Linked from
Related notes
- tuts/python3/stdlib_module/pathlib/UnsupportedOperation Linked here; links to this page; shared tags: #pathlib, #stdlib
- tuts/python3/stdlib_module/pathlib Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/pathlib/Path Linked here; shared tags: #pathlib, #stdlib
- tuts/python3/stdlib_module/pathlib/PosixPath Linked here; shared tags: #pathlib, #stdlib
- tuts/python3/stdlib_module/pathlib/PurePath Linked here; shared tags: #pathlib, #stdlib
- tuts/python3/stdlib_module/pathlib/PurePosixPath Linked here; shared tags: #pathlib, #stdlib
- tuts/python3/stdlib_module/pathlib/PureWindowsPath shared tags: #pathlib, #stdlib
- tuts/c/stdlib shared tags: #stdlib
- tuts/c/stdlib/assert shared tags: #stdlib
- tuts/c/stdlib/assert/assert shared tags: #stdlib