from typing import Union
from pathlib import Path
from typing import List
from typing import Any
import re


def filename_comparator(filename: Union[str, Path]) -> List[Any]:
    """Natural sort comparison key function for filename sorting."""
    return [int(s) if s.isdigit() else s.lower() for s in re.split(r'(\d+)', str(filename))]