Drop File in Folder will rename it partly

Hy Folks. I’m trying to convert a droplet (which works fine) in a folderaction.
I’m not good enough in scripting to understand. It seams that it works for the first File I drop but then it won’t work again.

I need different folders changing only pre defined digits of filenames (files/picts) I drop in to the specific folder.
Thanks for support
Daniel

script:


on adding folder items to this_folder after receiving added_items
	set prefix to (time of (current date))
	
	
	tell application "Finder"
		
		repeat with anItem in added_items
			--------------------------------------------
			-- example replace space 3
			set p1 to 3
			set k1 to "4"
			
			--don't change
			set sel to selection
			set neuerDateiname to ""
			set alterDateiname to ""
			
			repeat with naechsteDatei in sel
				try
					set alterDateiname to name of naechsteDatei
				end try
				
				set posZaehler to 0
				
				repeat with aChar in every character of alterDateiname
					set posZaehler to posZaehler + 1
					
					if posZaehler is equal to p1 then
						set neuerDateiname to (neuerDateiname & k1) as string
					else
						set neuerDateiname to (neuerDateiname & aChar) as string
					end if
					
				end repeat
				
				try
					set name of naechsteDatei to neuerDateiname
					set neuerDateiname to ""
					set alterDateiname to ""
				end try
				
			end repeat
			
			
			--------------------------------------------
			-- example replace space 1
			set p1 to 1
			set k1 to "1"
			
			--don't change
			set sel to selection
			set neuerDateiname to ""
			set alterDateiname to ""
			
			repeat with naechsteDatei in sel
				try
					set alterDateiname to name of naechsteDatei
				end try
				
				set posZaehler to 0
				
				repeat with aChar in every character of alterDateiname
					set posZaehler to posZaehler + 1
					
					if posZaehler is equal to p1 then
						set neuerDateiname to (neuerDateiname & k1) as string
					else
						set neuerDateiname to (neuerDateiname & aChar) as string
					end if
					
				end repeat
				
				try
					set name of naechsteDatei to neuerDateiname
					set neuerDateiname to ""
					set alterDateiname to ""
				end try
			end repeat
			
			
		end repeat
		
	end tell
end adding folder items to

… really no one got an idee? Help me - please.

ok, maybe my script is confusing - so I ask differently: I like to create a folder-action which changes for example the first and the third digit of a given name of a file.
Example: Original is called 222222_abc.CR2
I drop it in the folder with the action and it’s name is changing to 124222_abc.CR2. (only changing the first and third digit)

In the Script I should have the option to change the first 6 digit individually ore leave a digit unchanged. I need a set of folders doing different number changings.
Less confusing? How would you do this? Thanks the help.

I don’t get it. The Script below works fine for the first file I drop in to the folder with the new action attached. To drop multiply files ore an other file in the same folder will do no changes to the new dropped item name.
Why is the name changing only working for one dropped item but the: set comment of anItem to “Yes the function is working” is always working?
Somebody must know an answer - no?!
Saluda Daniel

on adding folder items to thisFolder after receiving addeditems
	repeat with anItem in addeditems
		tell application "Finder"
			set comment of anItem to "Yes the function is working"
			
			
			--------------------------------------------
			--example replace space 3
			set p1 to 3
			set k1 to "4"
			set sel to selection
			set neuerDateiname to ""
			set alterDateiname to ""
			
			repeat with naechsteDatei in sel
				try
					set alterDateiname to name of naechsteDatei
				end try
				
				set posZaehler to 0
				
				repeat with aChar in every character of alterDateiname
					set posZaehler to posZaehler + 1
					
					if posZaehler is equal to p1 then
						set neuerDateiname to (neuerDateiname & k1) as string
					else
						set neuerDateiname to (neuerDateiname & aChar) as string
					end if
					
				end repeat
				
				try
					set name of naechsteDatei to neuerDateiname
					set neuerDateiname to ""
					set alterDateiname to ""
				end try
				
			end repeat
			
			
			
		end tell
	end repeat
end adding folder items to