Error when trying to rename file

HELP! I’m trying to copy a file from one folder to another and then rename the copy but I keep getting “access not allowed” when trying to compile. What have I done wrong? BTW, “filePath” is just a filler, not the real file path.

Here’s my code:

on adding folder items to this_folder after receiving these_items
tell application “Finder”
repeat with this_item in these_items
duplicate this_item to “Macintosh HD:Users:techs03:Desktop:Receive:” --& newName
set oldName to name of this_item
set newName to text 1 thru 6 of oldName
display dialog oldName
display dialog newName
set name of file “filePath”&oldName to “filePath”&newName
end repeat
end tell
end adding folder items to

Any help is appreciated.

The compiler’s getting confused by the first concatenation in that line. It thinks you’re trying to concatenate oldName to the file “filepath” rather than to the string “filepath”. Some parentheses would help it out:

set name of file ("filePath" & oldName) to "filePath" & newName

The code you’re trying to create should look something like this, though it’ll need a bit more code if the file name has an extension you want to preserve:

on adding folder items to this_folder after receiving these_items
  tell application "Finder"
    repeat with this_item in these_items
      set newCopy to (duplicate this_item to folder "Receive" of the desktop)
      set oldName to name of this_item
      set newName to text 1 thru 6 of oldName
      set name of newCopy to newName
    end repeat
  end tell
end adding folder items to