Skip to content

ensure_file_exists

Creates a file and all parent directories if they don't exist already.

:param file: The file path.

Source code in library_analyzer/utils/_files.py
def ensure_file_exists(file: Path) -> None:
    """
    Creates a file and all parent directories if they don't exist already.

    :param file: The file path.
    """

    file.parent.mkdir(parents=True, exist_ok=True)
    file.touch(exist_ok=True)