def get_next_file_name(directory, prefix, extension):
    "Finds next available filename in directory by appending numbers to prefix.\n\n  E.g. If prefix is 'myfile', extenstion is '.png', and 'directory' already\n  contains 'myfile.png' and 'myfile1.png', this function will return\n  'myfile2.png'.\n\n  Args:\n    directory: Path to the relevant directory.\n    prefix: The filename prefix to use.\n    extension: String extension of the file, eg. '.mid'.\n  Returns:\n    String name of the file.\n  "
    name = ((((directory + '/') + prefix) + '.') + extension)
    i = 0
    while os.path.isfile(name):
        i += 1
        name = (((((directory + '/') + prefix) + str(i)) + '.') + extension)
    return name
Finds next available filename in directory by appending numbers to prefix.

E.g. If prefix is 'myfile', extenstion is '.png', and 'directory' already
contains 'myfile.png' and 'myfile1.png', this function will return
'myfile2.png'.

Args:
  directory: Path to the relevant directory.
  prefix: The filename prefix to use.
  extension: String extension of the file, eg. '.mid'.
Returns:
  String name of the file.
def get_next_file_name(directory, prefix, extension):
    "Finds next available filename in directory by appending numbers to prefix.\n\n  E.g. If prefix is 'myfile', extenstion is '.png', and 'directory' already\n  contains 'myfile.png' and 'myfile1.png', this function will return\n  'myfile2.png'.\n\n  Args:\n    directory: Path to the relevant directory.\n    prefix: The filename prefix to use.\n    extension: String extension of the file, eg. '.mid'.\n  Returns:\n    String name of the file.\n  "
    name = ((((directory + '/') + prefix) + '.') + extension)
    i = 0
    while os.path.isfile(name):
        i += 1
        name = (((((directory + '/') + prefix) + str(i)) + '.') + extension)
    return name