Filesystem utilities reference¶
temp_directory ¶
A context manager that creates a temporary directory and yields a path to it. Example:
Yields:
| Type | Description |
|---|---|
Path | The resolved path to the temporary directory, following all symlinks. |
temp_file ¶
A context manager that creates a temporary file and yields a path to it. Example:
Yields:
| Type | Description |
|---|---|
Path | The resolved path to the temporary file, following all symlinks. |
Path ¶
Bases: Path
long_id ¶
long_id: str
Returns a SHA-256 hashed, URL-safe base64 encoded representation of the current path. This is useful on case-insensitive filesystems to identify paths that are the same.
Caveat
This identifier considers the filesystem to be case-insensitive on macOS. Although that is not a technical guarantee, it is in practice true.
Returns:
| Type | Description |
|---|---|
str | A unique identifier for the current path. |
ensure_dir ¶
Ensure the current path is a directory. Equivalent to calling Path.mkdir with parents=True and exist_ok=True.
expand ¶
expand() -> Path
Expand the current path by resolving the user home directory and environment variables.
Returns:
| Type | Description |
|---|---|
Path | The new expanded path. |
write_atomic ¶
Atomically write data to the current path. This is equivalent to the following:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data | str | bytes | The data to write. | required |
Other Parameters:
| Name | Type | Description |
|---|---|---|
*args | Any | Additional arguments to pass to |
**kwargs | Any | Additional keyword arguments to pass to |
open_atomic ¶
as_cwd ¶
A context manager that changes the current working directory to the current path. Example:
Yields:
| Type | Description |
|---|---|
Path | The current path. |
hexdigest ¶
Returns a hexadecimal string representation of the file's digest. The algorithm used can be any algorithm supported by hashlib, as defined in hashlib. Defaults to sha256. Will raise FileNotFoundError if the path does not exist, and OSError if it is not a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algorithm | str | The hashing algorithm to use to calculate the digest, specified as a string. Must be a member of hashlib.algorithms_guaranteed. | 'sha256' |
buffer_size | int | None | The size, in bytes, of the in-memory buffer to use for reading the file while hashing. Defaults to None, which lets hashlib choose the buffer size. | None |