def check_and_get_directory(files):
    """
    Check if all provided files have the same directory and return it.

    :param files: A list of files to check and get directory from.
    :return: Base directory of the files.
    :raise: RuntimeException if files does not have same base directory.
    """
    if not files:
        raise ValueError('Files must not be empty!')

    head, *tail = files

    if not tail:
        return head.parent

    tail_parent = check_and_get_directory(tail)
    if head.parent == tail_parent:
        return head.parent

    raise RuntimeError('Files do not have the same directory: {} != {}'.format(head.parent, tail_parent))