import ntpath


def base_file_name(filename: str) -> str:
    """
    Extracts just the file name from a string that
    might contain a path.

    This will work on NT-based systems and *nix systems.
    It will work if the filename ends in a path delimter, e.g.
        "/home/tom/myfile.pdf/"
    It will NOT work if the filename contains escaped Unicode
    characters.

    *See*: https://stackoverflow.com/questions/8384737/extract-file-name-from-path-no-matter-what-the-os-path-format # NOQA

    Args:
        filename (str): Filename to parse.

    Returns:
        (str): Base file name.
    """
    escaped_file_name = filename.replace("\\", "\\\\")
    path_name, file_name = ntpath.split(escaped_file_name)
    return file_name or ntpath.basename(path_name)