polymerist.genutils.fileutils ============================= .. py:module:: polymerist.genutils.fileutils .. autoapi-nested-parse:: Utilities for manipulating Path-like objects and interfacing with directories and files Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/polymerist/genutils/fileutils/extensions/index /autoapi/polymerist/genutils/fileutils/filetree/index /autoapi/polymerist/genutils/fileutils/jsonio/index /autoapi/polymerist/genutils/fileutils/pathutils/index Attributes ---------- .. autoapisummary:: polymerist.genutils.fileutils.dir_tree Functions --------- .. autoapisummary:: polymerist.genutils.fileutils.is_empty polymerist.genutils.fileutils.assemble_path polymerist.genutils.fileutils.allow_string_paths polymerist.genutils.fileutils.allow_pathlib_paths polymerist.genutils.fileutils.prepend_parent polymerist.genutils.fileutils.detach_parent polymerist.genutils.fileutils.exchange_parent polymerist.genutils.fileutils.local_rename polymerist.genutils.fileutils.local_restem polymerist.genutils.fileutils.startfile polymerist.genutils.fileutils.temporary_cd polymerist.genutils.fileutils.clear_dir Package Contents ---------------- .. py:function:: is_empty(path: pathlib.Path) -> bool 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) .. py:function:: assemble_path(directory: pathlib.Path, prefix: str, extension: str, postfix: str = '') -> pathlib.Path Combine output, naming, descriptive, and filetype info to generate a complete Path .. py:function:: allow_string_paths(funct: Callable[[Concatenate[pathlib.Path, Params]], T]) -> Callable[[Concatenate[Union[pathlib.Path, str], Params]], T] Modifies a function which expects a Path as its first argument to also accept string-paths .. py:function:: allow_pathlib_paths(funct: Callable[[Concatenate[str, Params]], T]) -> Callable[[Concatenate[Union[pathlib.Path, str], Params]], T] Modifies a function which expects a string path as its first argument to also accept canonical pathlib Paths .. py:function:: prepend_parent(path: pathlib.Path, new_parent: pathlib.Path) -> pathlib.Path Prepends a parent tree to an existing path .. py:function:: detach_parent(path: pathlib.Path, old_parent: pathlib.Path) -> pathlib.Path Cuts off a parent tree from an existing path .. py:function:: exchange_parent(path: pathlib.Path, old_parent: pathlib.Path, new_parent: pathlib.Path) -> pathlib.Path Exchanges the parent tree of a path for another parent tree .. py:function:: local_rename(path: pathlib.Path, new_name: str) -> pathlib.Path Performs file rename relative to the parent directory (NOT the cwd) .. py:function:: local_restem(path: pathlib.Path, new_stem: str) -> pathlib.Path Performs file rename relative to the parent directory (NOT the cwd), preserving the extension of the original file .. py:data:: dir_tree .. py:function:: startfile(path: pathlib.Path) -> None Replacement for os.startfile() functionality, since none natively exists in Linux .. py:function:: temporary_cd(dir_path: Optional[pathlib.Path]) -> Generator[pathlib.Path, None, None] Context manager for temporarily changing the current working directory of code wrapped in a "with" block .. py:function:: clear_dir(path: pathlib.Path) -> None Recursively clear contents of a directory at the given path (depth-first)