Skip to content

Utils

blipss.utils.general_utils

General filesystem utility functions

check_file_exists(filepath)

Return True if the given path points to an existing file, False otherwise.

Parameters:

Name Type Description Default
filepath Path

Filesystem path to check

required

Returns:

Type Description
bool

True if filepath exists and is a regular file, False otherwise

Source code in blipss/utils/general_utils.py
25
26
27
28
29
30
31
32
33
34
35
def check_file_exists(filepath: Path) -> bool:
    """
    Return True if the given path points to an existing file, False otherwise.

    Args:
        filepath: Filesystem path to check

    Returns:
        True if ``filepath`` exists and is a regular file, False otherwise
    """
    return filepath.is_file()

ensure_path_exists(path)

Create a directory at the given path, handling file and missing-parent cases.

If the path already exists as a directory, returns immediately. If the path points to an existing file, creates the file's parent directory tree instead. Otherwise creates the directory along with any missing intermediate parents.

Parameters:

Name Type Description Default
path Path

Filesystem path at which to create the directory

required
Source code in blipss/utils/general_utils.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
def ensure_path_exists(path: Path) -> None:
    """
    Create a directory at the given path, handling file and missing-parent cases.

    If the path already exists as a directory, returns immediately. If the path
    points to an existing file, creates the file's parent directory tree instead.
    Otherwise creates the directory along with any missing intermediate parents.

    Args:
        path: Filesystem path at which to create the directory
    """
    if path.is_dir():
        return
    if path.is_file():
        path.parent.mkdir(parents=True, exist_ok=True)
        return
    path.mkdir(parents=True, exist_ok=True)