pathlib2#

class pathlib_mate.pathlib2.PurePath(*args: Type[PurePath])[source]#

PurePath represents a filesystem path and offers operations which don’t imply any actual filesystem I/O. Depending on your system, instantiating a PurePath will return either a PurePosixPath or a PureWindowsPath object. You can also instantiate either of these classes directly, regardless of your system.

as_posix()[source]#

Return the string representation of the path with forward (/) slashes.

as_uri()[source]#

Return the path as a ‘file’ URI.

property drive#

The drive prefix (letter or UNC path), if any.

property root#

The root of the path, if any.

property anchor#

The concatenation of the drive and root, or ‘’.

property name#

The final path component, if any.

property suffix#

The final component’s last suffix, if any.

property suffixes#

A list of the final component’s suffixes, if any.

property stem#

The final path component, minus its last suffix.

with_name(name)[source]#

Return a new path with the file name changed.

Return type:

Path

with_suffix(suffix)[source]#

Return a new path with the file suffix changed. If the path has no suffix, add given suffix. If the given suffix is an empty string, remove the suffix from the path.

Return type:

Path

relative_to(*other)[source]#

Return the relative path to another path identified by the passed arguments. If the operation is not possible (because this is not a subpath of the other path), raise ValueError.

Return type:

Path

property parts#

An object providing sequence-like access to the components in the filesystem path.

joinpath(*args)[source]#

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 is anchored).

Return type:

Path

property parent#

The logical parent of the path.

Return type:

Path

property parents#

A sequence of this path’s logical parents.

Return type:

Sequence[Path]

is_absolute()[source]#

True if the path is absolute (has both a root and, if applicable, a drive).

Return type:

bool

is_reserved()[source]#

Return True if the path contains one of the special names reserved by the system, if any.

Return type:

bool

match(path_pattern)[source]#

Return True if this path matches the given pattern.

Return type:

bool

class pathlib_mate.pathlib2.PurePosixPath(*args: Type[PurePath])[source]#
class pathlib_mate.pathlib2.PureWindowsPath(*args: Type[PurePath])[source]#

PurePath subclass for Windows systems.

On a Windows system, instantiating a PurePath should return this object. However, you can also instantiate it directly on any system.

class pathlib_mate.pathlib2.Path(*args: Type[Path], **kwargs: Union[str, PurePath, PathlibPath])[source]#

PurePath subclass that can make system calls.

Path represents a filesystem path but unlike PurePath, also offers methods to do system calls on path objects. Depending on your system, instantiating a Path will return either a PosixPath or a WindowsPath object. You can also instantiate a PosixPath or WindowsPath directly, but cannot instantiate a WindowsPath on a POSIX system or vice versa.

classmethod cwd()[source]#

Return a new path pointing to the current working directory (as returned by os.getcwd())

Return type:

Path

classmethod home()[source]#

Return a new path pointing to the user’s home directory (as returned by os.path.expanduser(‘~’)).

Return type:

Path

samefile(other_path)[source]#

Return whether other_path is the same or not as this file (as returned by os.path.samefile()).

Return type:

bool

iterdir()[source]#

Iterate over the files in this directory. Does not yield any result for the special paths ‘.’ and ‘..’.

Return type:

Iterable[Path]

glob(pattern)[source]#

Iterate over this subtree and yield all existing files (of any kind, including directories) matching the given relative pattern.

Return type:

Iterable[Path]

rglob(pattern)[source]#

Recursively yield all existing files (of any kind, including directories) matching the given relative pattern, anywhere in this subtree.

Return type:

Iterable[Path]

absolute()[source]#

Return an absolute version of this path. This function works even if the path doesn’t point to anything.

No normalization is done, i.e. all ‘.’ and ‘..’ will be kept along. Use resolve() to get the canonical path to a file.

Return type:

Path

resolve(strict=False)[source]#

Make the path absolute, resolving all symlinks on the way and also normalizing it (for example turning slashes into backslashes under Windows).

Return type:

Path

stat()[source]#

Return the result of the stat() system call on this path, like os.stat() does.

owner()[source]#

Return the login name of the file owner.

group()[source]#

Return the group name of the file gid.

open(mode='r', buffering=-1, encoding=None, errors=None, newline=None)[source]#

Open the file pointed by this path and return a file object, as the built-in open() function does.

read_bytes()[source]#

Open the file in bytes mode, read it, and close the file.

Return type:

bytes

read_text(encoding=None, errors=None)[source]#

Open the file in text mode, read it, and close the file.

Return type:

str

write_bytes(data)[source]#

Open the file in bytes mode, write to it, and close the file.

write_text(data, encoding=None, errors=None, newline=None)[source]#

Open the file in text mode, write to it, and close the file.

touch(mode=438, exist_ok=True)[source]#

Create this file with the given access mode, if it doesn’t exist.

mkdir(mode=511, parents=False, exist_ok=False)[source]#

Create a new directory at this given path.

chmod(mode)[source]#

Change the permissions of the path, like os.chmod().

lchmod(mode)[source]#

Like chmod(), except if the path points to a symlink, the symlink’s permissions are changed, rather than its target’s.

Remove this file or link. If the path is a directory, use rmdir() instead.

rmdir()[source]#

Remove this directory. The directory must be empty.

lstat()[source]#

Like stat(), except if the path points to a symlink, the symlink’s status information is returned, rather than its target’s.

rename(target)[source]#

Rename this path to the given path.

replace(target)[source]#

Rename this path to the given path, clobbering the existing destination if it exists.

Make this path a symlink pointing to the given path. Note the order of arguments (self, target) is the reverse of os.symlink’s.

exists()[source]#

Whether this path exists.

Return type:

bool

is_dir()[source]#

Whether this path is a directory.

Return type:

bool

is_file()[source]#

Whether this path is a regular file (also True for symlinks pointing to regular files).

Return type:

bool

is_mount()[source]#

Check if this path is a POSIX mount point

Return type:

bool

Whether this path is a symbolic link.

Return type:

bool

is_block_device()[source]#

Whether this path is a block device.

Return type:

bool

is_char_device()[source]#

Whether this path is a character device.

Return type:

bool

is_fifo()[source]#

Whether this path is a FIFO.

Return type:

bool

is_socket()[source]#

Whether this path is a socket.

Return type:

bool

expanduser()[source]#

Return a new path with expanded ~ and ~user constructs (as returned by os.path.expanduser)

Return type:

Path

class pathlib_mate.pathlib2.PosixPath(*args: Type[Path], **kwargs: Union[str, PurePath, PathlibPath])[source]#

Path subclass for non-Windows systems.

On a POSIX system, instantiating a Path should return this object.

class pathlib_mate.pathlib2.WindowsPath(*args: Type[Path], **kwargs: Union[str, PurePath, PathlibPath])[source]#

Path subclass for Windows systems.

On a Windows system, instantiating a Path should return this object.

owner()[source]#

Return the login name of the file owner.

group()[source]#

Return the group name of the file gid.

is_mount()[source]#

Check if this path is a POSIX mount point

Return type:

bool