from pathlib import Path


def pathwalk(dir: Path) -> list[Path]:
    """Obtain all file paths in a directory and all it's subdirectories.

    Function is recursive.

    Args:
        `dir` (`Path`): The starting, top-level directory to walk.

    Returns:
        (list): Containing Path objects of all filepaths in `dir`.
    """
    # Obtain all folders within dir.
    subdir_folders = [item for item in dir.iterdir() if item.is_dir()]
    # Obtain all files within dir.
    subfiles = [item for item in dir.iterdir() if item.is_file()]

    # Use recursion to get paths to all files within dir.
    if subdir_folders:
        # Obtain file paths from the subdirectories within dir and
        # add them to the subfiles list.
        for folder in subdir_folders:
            subfiles.extend(pathwalk(folder))
    # When dir contains no folder, return the subfiles list.
    return subfiles