polymerist.genutils.fileutils.pathutils
Utilities for editing, augmenting, and querying Paths
Attributes
Functions
|
Allow functions which expect Paths to also accept strings |
|
Allow functions which expect strings paths to also accept Paths |
|
Modifies a function which expects a Path as its first argument to also accept string-paths |
|
Modifies a function which expects a string path as its first argument to also accept canonical pathlib Paths |
|
Check if a directory contains no files |
|
Check if a file contains no data |
|
Flexibly check whether a path is "empty" |
|
Combine output, naming, descriptive, and filetype info to generate a complete Path |
|
Separate the dot from file path. Returns the original suffix if not dot is present |
|
Asserts that a path has a suffix, appending a specified default suffix if none exists |
|
Prepends a parent tree to an existing path |
|
Cuts off a parent tree from an existing path |
|
Exchanges the parent tree of a path for another parent tree |
|
Performs file rename relative to the parent directory (NOT the cwd) |
|
Performs file rename relative to the parent directory (NOT the cwd), preserving the extension of the original file |
Module Contents
- polymerist.genutils.fileutils.pathutils.T
- polymerist.genutils.fileutils.pathutils.Params
- polymerist.genutils.fileutils.pathutils.aspath(path: str | pathlib.Path) pathlib.Path[source]
Allow functions which expect Paths to also accept strings
- polymerist.genutils.fileutils.pathutils.asstrpath(strpath: str | pathlib.Path) str[source]
Allow functions which expect strings paths to also accept Paths
- polymerist.genutils.fileutils.pathutils.allow_string_paths(funct: Callable[[Concatenate[pathlib.Path, Params]], T]) Callable[[Concatenate[pathlib.Path | str, Params]], T][source]
Modifies a function which expects a Path as its first argument to also accept string-paths
- polymerist.genutils.fileutils.pathutils.allow_pathlib_paths(funct: Callable[[Concatenate[str, Params]], T]) Callable[[Concatenate[pathlib.Path | str, Params]], T][source]
Modifies a function which expects a string path as its first argument to also accept canonical pathlib Paths
- polymerist.genutils.fileutils.pathutils.is_empty_dir(dirpath: pathlib.Path) bool[source]
Check if a directory contains no files
- polymerist.genutils.fileutils.pathutils.is_empty_file(filepath: pathlib.Path) bool[source]
Check if a file contains no data
- polymerist.genutils.fileutils.pathutils.is_empty(path: pathlib.Path) bool[source]
Flexibly check whether a path is “empty” If path point to a file, returns whether the file contains data If path points to a directory, returns whether the directory contains any files (empty or otherwise)
- polymerist.genutils.fileutils.pathutils.assemble_path(directory: pathlib.Path, prefix: str, extension: str, postfix: str = '') pathlib.Path[source]
Combine output, naming, descriptive, and filetype info to generate a complete Path
- polymerist.genutils.fileutils.pathutils.dotless(path: pathlib.Path) str[source]
Separate the dot from file path. Returns the original suffix if not dot is present
- polymerist.genutils.fileutils.pathutils.default_suffix(path: pathlib.Path, suffix: str) pathlib.Path[source]
Asserts that a path has a suffix, appending a specified default suffix if none exists
- polymerist.genutils.fileutils.pathutils.prepend_parent(path: pathlib.Path, new_parent: pathlib.Path) pathlib.Path[source]
Prepends a parent tree to an existing path
- polymerist.genutils.fileutils.pathutils.detach_parent(path: pathlib.Path, old_parent: pathlib.Path) pathlib.Path[source]
Cuts off a parent tree from an existing path
- polymerist.genutils.fileutils.pathutils.exchange_parent(path: pathlib.Path, old_parent: pathlib.Path, new_parent: pathlib.Path) pathlib.Path[source]
Exchanges the parent tree of a path for another parent tree