polymerist.genutils.fileutils.pathutils

Utilities for editing, augmenting, and querying Paths

Attributes

T

Params

Functions

aspath(→ pathlib.Path)

Allow functions which expect Paths to also accept strings

asstrpath(→ str)

Allow functions which expect strings paths to also accept Paths

allow_string_paths(...)

Modifies a function which expects a Path as its first argument to also accept string-paths

allow_pathlib_paths(...)

Modifies a function which expects a string path as its first argument to also accept canonical pathlib Paths

is_empty_dir(→ bool)

Check if a directory contains no files

is_empty_file(→ bool)

Check if a file contains no data

is_empty(→ bool)

Flexibly check whether a path is "empty"

assemble_path(→ pathlib.Path)

Combine output, naming, descriptive, and filetype info to generate a complete Path

dotless(→ str)

Separate the dot from file path. Returns the original suffix if not dot is present

default_suffix(→ pathlib.Path)

Asserts that a path has a suffix, appending a specified default suffix if none exists

prepend_parent(→ pathlib.Path)

Prepends a parent tree to an existing path

detach_parent(→ pathlib.Path)

Cuts off a parent tree from an existing path

exchange_parent(→ pathlib.Path)

Exchanges the parent tree of a path for another parent tree

local_rename(→ pathlib.Path)

Performs file rename relative to the parent directory (NOT the cwd)

local_restem(→ pathlib.Path)

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

polymerist.genutils.fileutils.pathutils.local_rename(path: pathlib.Path, new_name: str) pathlib.Path[source]

Performs file rename relative to the parent directory (NOT the cwd)

polymerist.genutils.fileutils.pathutils.local_restem(path: pathlib.Path, new_stem: str) pathlib.Path[source]

Performs file rename relative to the parent directory (NOT the cwd), preserving the extension of the original file