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