def is_within_directory(directory: Path, target: Path) -> bool:
    """Check if a target path is located within a given directory.

    Args:
        directory: Path of the parent directory
        target: Path to check

    Returns:
        ``True`` if target is within directory, ``False`` otherwise
    """
    abs_directory = directory.resolve()
    abs_target = target.resolve()

    # TODO(djdameln): Replace with pathlib is_relative_to after switching to
    # Python 3.10
    # CVS-122655
    prefix = os.path.commonprefix([abs_directory, abs_target])
    return prefix == str(abs_directory)
Check if a target path is located within a given directory.

    Args:
        directory: Path of the parent directory
        target: Path to check

    Returns:
        ``True`` if target is within directory, ``False`` otherwise
    
src/anomalib/data/utils/download.py