import ntpath


def leafname(path):
    """ gets the local filename if a file or foldername if a folder
    :param path: the filepath from which to extract the leaf name segment
    :return: the last name segment in the filepath
    """
    head, tail = ntpath.split(path)
    return tail or ntpath.basename(head)