polymerist.genutils.fileutils

Utilities for manipulating Path-like objects and interfacing with directories and files

Submodules

Attributes

dir_tree

Functions

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

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

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

startfile(→ None)

Replacement for os.startfile() functionality, since none natively exists in Linux

temporary_cd(→ Generator[pathlib.Path, None, None])

Context manager for temporarily changing the current working directory of code wrapped in a "with" block

clear_dir(→ None)

Recursively clear contents of a directory at the given path (depth-first)

Package Contents

polymerist.genutils.fileutils.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.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.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.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.prepend_parent(path: pathlib.Path, new_parent: pathlib.Path) pathlib.Path[source]

Prepends a parent tree to an existing path

polymerist.genutils.fileutils.detach_parent(path: pathlib.Path, old_parent: pathlib.Path) pathlib.Path[source]

Cuts off a parent tree from an existing path

polymerist.genutils.fileutils.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.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.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

polymerist.genutils.fileutils.dir_tree
polymerist.genutils.fileutils.startfile(path: pathlib.Path) None[source]

Replacement for os.startfile() functionality, since none natively exists in Linux

polymerist.genutils.fileutils.temporary_cd(dir_path: pathlib.Path | None) Generator[pathlib.Path, None, None][source]

Context manager for temporarily changing the current working directory of code wrapped in a “with” block

polymerist.genutils.fileutils.clear_dir(path: pathlib.Path) None[source]

Recursively clear contents of a directory at the given path (depth-first)