def filename_fix_existing(filename, dirname):
name, ext = filename.rsplit('<STR_LIT:.>', <NUM_LIT:1>)<EOL>names = [x for x in os.listdir(dirname) if x.startswith(name)]<EOL>names = [x.rsplit('<STR_LIT:.>', <NUM_LIT:1>)[<NUM_LIT:0>] for x in names]<EOL>suffixes = [x.replace(name, '<STR_LIT>') for x in names]<EOL>suffixes = [x[<NUM_LIT:2>:-<NUM_LIT:1>] for x in suffixes<EOL>if x.startswith('<STR_LIT>') and x.endswith('<STR_LIT:)>')]<EOL>indexes = [int(x) for x in suffixes<EOL>if set(x) <= set('<STR_LIT>')]<EOL>idx = <NUM_LIT:1><EOL>if indexes:<EOL><INDENT>idx += sorted(indexes)[-<NUM_LIT:1>]<EOL><DEDENT>return '<STR_LIT>'.format(name, idx, ext)<EOL>
Expands name portion of filename with numeric ' (x)' suffix to
    return filename that doesn't exist already.