Could someone show me how "adaptive renaming" work?


i want to know how to create adaptive suffix, that are “content aware” of the situation, to avoid erasing object that have the same names. i think that this is a classic use of python, could someone explain or give me a link to a explanation/ tutorial that can help me understand how this adaptive renaming system work ?

for example in this code below im automatically creating a save as copy in the directory file.

import bpy
import os

    os.mkdir(os.path.dirname("\\save as copy\\")
    print('directory already created')

Dir = os.path.dirname( + "\\save as copy\\"

bpy.ops.wm.save_as_mainfile(copy=True, filepath= Dir +"Copy.blend")

the only problem is that it erase the previous .blend everytime i do the action, id much prefer to implement an adaptive suffix, that create “copy 001” if copy already exist; “copy 002” if 001 already exist… i could do that with condition but i dont know how to reproduce the steps indefinitely.

in a precedent code someone show me a way to do this ? i dont know if its specific to the situation or not, but i didnt understand how to reproduce thoses act for my situation

import bpy

context = bpy.context
scene = context.scene
A = context.object

i = 1
pref = "%s Mirror " %

name = "%s%d" % (pref, i)
while A.modifiers.get(name):    
    i += 1
    name = "%s%d" % (pref, i)

A.modifiers[len(A.modifiers)-1].name = name
bpy.ops.transform.resize(value=(0.01, 1, 1), constraint_axis=(True, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='ENABLED', proportional_edit_falloff='SMOOTH', proportional_size=0.00439353)
E = bpy.context.selected_objects[0] = name
A.modifiers[name].mirror_object = E

i just know that its related to this part of the code

i = 1
i += 1

i simply didnt get it

thanks :neutral_face: