import os
import glob
from typing import List


def filesByExtension(source_path: str, extension: str) -> List[str]:
    files = []
    files.extend(glob.glob(f"{source_path}/**/*.{extension.lower()}", recursive=True))
    files.extend(glob.glob(f"{source_path}**/*.{extension.upper()}", recursive=True))
    return files


def _findCaptionFile(directory: str, basename: str) -> str:
    possibility = os.path.join(directory, basename + ".md")
    if os.path.exists(possibility):
        return possibility
    possibility = os.path.join(directory, basename + ".MD")
    if os.path.exists(possibility):
        return possibility
    raise FileNotFoundError(possibility)