from pathlib import Path


def count_files(path, glob=None) -> int:
    """Return the number of files in a given directory."""
    path = Path(path)
    files = path.glob(glob) if glob else path.iterdir()
    return sum(1 for file in files if file.is_file())