Check Exists

Check whether the specified path of a file or folder exists.

Check Exists


Processing

Verifies whether a specified file or folder path exists in the filesystem.

Inputs

path
The file or folder path to check for existence.

Inputs Types

Input Types
path Str, Path

You can check the list of supported types here: Available Type Hints.

Outputs

exists
A boolean indicating whether the specified path exists.

Outputs Types

Output Types
exists Bool

You can check the list of supported types here: Available Type Hints.

Options

The Check Exists brick contains some changeable options:

Verbose
Enables detailed logging about the path existence check, including whether the path is a file, directory, or does not exist.
import logging
from coded_flows.types import Str, Path, Union, Bool

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)


def check_exists(path: Union[Str, Path], options=None) -> Bool:
    brick_display_name = "Check Exists"
    options = options or {}
    verbose = options.get("verbose", True)
    exists = False
    try:
        path_obj = Path(path)
        verbose and logger.info(
            f"[{brick_display_name}] Checking path existence: '{path_obj}'."
        )
        exists = path_obj.exists()
        if verbose:
            if exists:
                if path_obj.is_file():
                    logger.info(f"[{brick_display_name}] File exists: '{path_obj}'.")
                elif path_obj.is_dir():
                    logger.info(
                        f"[{brick_display_name}] Directory exists: '{path_obj}'."
                    )
                else:
                    logger.info(
                        f"[{brick_display_name}] Path exists (special type): '{path_obj}'."
                    )
            else:
                logger.info(
                    f"[{brick_display_name}] Path does not exist: '{path_obj}'."
                )
    except Exception as e:
        verbose and logger.error(f"[{brick_display_name}] Error checking path.")
        raise
    return exists

Brick Info

version v0.1.4
python 3.10, 3.11, 3.12, 3.13
requirements
    -