polymerist.genutils.fileutils
Utilities for manipulating Path-like objects and interfacing with directories and files
Submodules
Attributes
Functions
|
Flexibly check whether a path is "empty" |
|
Combine output, naming, descriptive, and filetype info to generate a complete Path |
|
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 |
|
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 |
|
Replacement for os.startfile() functionality, since none natively exists in Linux |
|
Context manager for temporarily changing the current working directory of code wrapped in a "with" block |
|
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