Bug - not recognizing that file exists

I have a bug in a script. I thought I had written the script to check to see if a file already exists, and to change the name if it does. But I’m getting “File exists” errors anyway. Can anyone see what I did wrong?

			tell application "Finder"
				-- make the copy
				set theDuplicateFile to duplicate fileToDupe to destFolder replacing «constant vwbycflc»
				set theDuplicateFile to theDuplicateFile as alias -- typecast
				set thisFileDupeInfo to (info for theDuplicateFile) -- get file info for the copied file
				set theExt to the name extension of thisFileDupeInfo -- get the file's extension
				set newFilename to (thisOffender & "." & theExt)
				set newFilePath to (nooffFolderString & ":" & newFilename)
				if not (exists newFilePath) then
					set the name of theDuplicateFile to newFilename -- change the file's name
				else
					set newFilename to (thisOffender & "_2." & theExt)
					set newFilePath to (nooffFolderString & ":" & newFilename)
				end if
			end tell

Hi,

that’s a scripter’s bug. :wink:
You’re going to check the existence of a string (newFilePath) instead of a file object. Add the keyword file


.
  if not (exists file newFilePath) then
.

BTW: in a Finder tell block you can get the name extension directly, info for is not needed.