def filename2format(fn, places=3):
    """Converts a filename to a format string capable of adding an index after the basename"""
    index = "{:0" + str(places) + "d}" if places else "{}"
    last_dot = fn.rfind(".")
    if last_dot < 0: # not found
        return fn + index
    else:
        return fn[0:last_dot] + index + fn[last_dot:]