from pathlib import Path


def get_last_file(base_dir, pattern):
    """Return the last file in a folder that match the given pattern.

    Parameters
    ----------
    base_dir: str or Path
        Base directory to search for a matching file.
    pattern: str
        Pattern used in glob to find files.

    Returns
    -------
    fname: str, name of a matching file.
    """
    base_dir = Path(base_dir)

    return sorted(base_dir.glob(pattern),
                  key=lambda x: x.stat().st_ctime, reverse=True)[0]