import pathlib


def find_root(folder: pathlib.Path) -> pathlib.Path:
    """
    Finds the root of the dataset files

    :param folder: Folder to check
    :return: The folder parent of the "static" and "dynamic" folders
    :raise IOError: Path not found
    """
    if not folder.is_dir():
        raise IOError(f"{folder} is not a directory")

    if (folder / "static").exists() and (folder / "dynamic").exists():
        # Found it
        return folder

    for child in folder.iterdir():
        if folder.is_dir():
            try:
                return find_root(child)
            except IOError:
                continue
    else:
        raise IOError(f"Root not found under {folder}")