from pathlib import Path


def saveString(string, folder='.', filename='Untitled.txt'):
    """Save string to txt file.

    Args:
        folder (str or pathlib.Path, optional): path to save file. If no path
            is given, current working directory is used.
        filename (str, optional): file name.

    Returns:
        1 if successful or -1 otherwise.
    """
    # check folder exist
    if folder == '.':
        folder = Path.cwd()
    else:
        folder = Path(folder)
        if folder.is_dir() == False:
            print(f'ERROR: {folder} does not exist.')
            print('File not created.')
            return -1

    f = open(str(folder/filename), 'w')
    f.write(string)
    f.close()
    return 1