Error naming a file

Should be elementary by now - but for some reason, I need another set of eyes on this.

tell application "Finder"
	if itExists = true then
		repeat with eachFile from x to numFiles
			set fileNameX to (item x of filenames)
			set name of (folderPath & thisFolder & ":" & fileNameX) to (folderName & "_" & fileNameX)
		end repeat
	else
		doSomethingElse
	end if
end tell

When itExists=true, I am generating the following error when I get to the “set name of” command -

However, the file is actually renamed, but the error kills the script… anyone know why the error would be generating in the first place?

The usual error, I expect. You’re trying to rename a string. :slight_smile:

And it’s the same string each time round the repeat.

Scott:

Nigel is right, look at your setFileName line; it uses the x variable, which never changes. Also, whenever you want Finder to do something with a file, you need to preceded the variable with the term [file] as in, set name of file xxx to yyy or something like that.

Give it another go and see what happens.