Skip to content

Files

files

Functions

ensure_containing_folder(filename)

Ensure the folder containing this file exists. Nothing happens if already present.

Parameters:

Name Type Description Default
filename PATH_TYPE

The path to the file for which the containing folder should be created

required
Source code in geograypher/utils/files.py
def ensure_containing_folder(filename: PATH_TYPE):
    """Ensure the folder containing this file exists. Nothing happens if already present.

    Args:
        filename (PATH_TYPE): The path to the file for which the containing folder should be created
    """
    # Cast the file to a pathlib Path
    filename = Path(filename)
    # Get the folder above it
    containing_folder = filename.parent
    # Create this folder and all parent folders if needed. Nothing happens if it already exists
    ensure_folder(containing_folder)

ensure_folder(folder)

Ensure this folder, and parent folders, exist. Nothing happens if already present

Parameters:

Name Type Description Default
folder PATH_TYPE

Path to folder to ensure exists

required
Source code in geograypher/utils/files.py
def ensure_folder(folder: PATH_TYPE):
    """Ensure this folder, and parent folders, exist. Nothing happens if already present

    Args:
        folder (PATH_TYPE): Path to folder to ensure exists
    """
    folder = Path(folder)
    # Create this folder and all parent folders if needed. Nothing happens if it already exists
    folder.mkdir(parents=True, exist_ok=True)