auto-renaming files when duplicate exists

How can I not find a ready-made solution for automatically renaming files when exporting and there are duplicates ?

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
obaida's picture

Function

	fn CheckName old_name Save_Path Extension = (
    	local digits = #() , pattern_name = ""
     	if not doesFileExist (Save_Path + old_name + Extension) then new_name = old_name else (
			digits = filterString old_name "_"
			if digits.count > 1 and digits[digits.count] as number != undefined then (
				pattern_name = trimright old_name "0123456789"
				new_name = pattern_name + ((digits[digits.count] as number + 1) as string)
				new_name = CheckName new_name Save_Path Extension
			)
			else new_name = CheckName (old_name + "_1") Save_Path Extension
		)
		new_name
	)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.