import csv


def save_file(path, content, mode='w', format_='json'):
    """
        Save exported items to a file
    """

    # Save to file
    try:
        file = open(path, mode)

        if format_ == 'json':
            file.write(content)
            file.close()
        else:
            writer = csv.writer(file)
            writer.writerows(content)

        print("The vault has been exported to the file `%s`." % (path))
    except Exception as e:
        print("The vault could not be exported to the file `%s`." % (path))
        print(e)

        return False

    return True