def _prepare_files_labels(
    path: str | Path,
    path_type: str,
    extensions: tuple[str, ...] | None = None,
) -> tuple[list, list]:
    """Get lists of filenames and corresponding labels from a directory.

    Args:
        path: Path to directory containing images
        path_type: Type of images ("normal", "abnormal", "normal_test")
        extensions: Allowed file extensions. Defaults to ``IMG_EXTENSIONS``

    Returns:
        Tuple containing:
            - List of image filenames
            - List of corresponding labels

    Raises:
        RuntimeError: If no valid images found or extensions don't start with dot

    Example:
        >>> files, labels = _prepare_files_labels("./normal", "normal", (".png",))
        >>> len(files) == len(labels)
        True
    """
    path = _check_and_convert_path(path)
    if extensions is None:
        extensions = IMG_EXTENSIONS

    if isinstance(extensions, str):
        extensions = (extensions,)

    if not all(extension.startswith(".") for extension in extensions):
        msg = f"All extensions {extensions} must start with the dot"
        raise RuntimeError(msg)

    filenames = [
        f
        for f in path.glob("**/*")
        if f.suffix in extensions and not f.is_dir() and not any(part.startswith(".") for part in f.parts)
    ]
    if not filenames:
        msg = f"Found 0 {path_type} images in {path} with extensions {extensions}"
        raise RuntimeError(msg)

    labels = [path_type] * len(filenames)

    return filenames, labels
Get lists of filenames and corresponding labels from a directory.

    Args:
        path: Path to directory containing images
        path_type: Type of images ("normal", "abnormal", "normal_test")
        extensions: Allowed file extensions. Defaults to ``IMG_EXTENSIONS``

    Returns:
        Tuple containing:
            - List of image filenames
            - List of corresponding labels

    Raises:
        RuntimeError: If no valid images found or extensions don't start with dot

    Example:
        >>> files, labels = _prepare_files_labels("./normal", "normal", (".png",))
        >>> len(files) == len(labels)
        True
    
src/anomalib/data/utils/path.py