Applescript giving error 1728 when checking if file exists

applescript

I'm trying to make compressing a video file using HandBrake easier through applescript and have been basing most of the code off of templates I've found.
At this point in the code, the user has specified the source file and the destination folder.
Instead of HandBrakeCLI just blindly overwriting a file with the same name in the destination folder, I wanted Finder to do a check and, if a file with the same does already exist in the destination folder, then I wanted to have the filename appended with the current date and time before the extension.
Everything worked fine until I started adding the "if exists" code.

Here's the chunk of code:

tell application "Finder"
    set newFilepathPOSIX to POSIX path of dest_folder
    set newFilepathPOSIX to newFilepathPOSIX & "video.mp4"
    -- Check if file with same name exists
    if exists file newFilepathPOSIX then
        display dialog "There is already a file named \"video.mp4\". Do you want to replace the file?" buttons {"Quit", "No", "Yes"} cancel button 1
        if result = {button returned:"No"} then
            set newFilepathPOSIX to POSIX path of dest_folder
            set newFilepathPOSIX to newFilepathPOSIX & "video" & getDateAsString & ".mp4"
        end if
    end if
    set newFilepathPOSIX to quoted form of newFilepathPOSIX
    set shellCommand to "/Volumes/Flash Drive/HandBrakeCLI -i " & origFilepathPOSIX & " -o " & newFilepathPOSIX & " --preset=\"Classic\""
end tell

to getDateAsString from t
    set creationDateString to year of t as string
    set creationDateString to creationDateString & text -2 thru -1 of ("0" & getMonthNum(t) as string)
    set creationDateString to creationDateString & text -2 thru -1 of ("0" & day of t as string)
    set creationDateString to creationDateString & text -2 thru -1 of ("0" & hours of t as string)
    set creationDateString to creationDateString & text -2 thru -1 of ("0" & minutes of t as string)
    set creationDateString to creationDateString & text -2 thru -1 of ("0" & seconds of t as string)
    return creationDateString
end getDateAsString

Here's what it returns:

exists file "/Users/me/Box Documents/My Folder/video.mp4"
    --> false

If I add "as POSIX file" to the "if exists" line, this is what it returns:

get file "/Users/me/Box Documents/My Folder/video.mp4"
    --> error number -1728 from file "/Users/me/Box Documents/My Folder/video.mp4"
exists file "My HD:Users:me:Box Documents:My Folder:video.mp4"
    --> true
display dialog "There is already a file named \"video.mp4\". Do you want to replace the file?" buttons {"Quit", "No", "Yes"} cancel button 1
    --> {button returned:"No"}

After this, it errored out.
Totally new at this so hopefully I've given enough detail without giving away way too much detail.

Best Answer

Try:

set dest_folder to POSIX path of dest_folder
set newFilepathPOSIX to dest_folder & "video.mp4"

tell application "System Events" to exists file newFilepathPOSIX
if the result then
    display dialog "There is already a file named \"video.mp4\". Do you want to replace the file?" buttons {"Quit", "No", "Yes"} cancel button 1
    if button returned of the result = "No" then
        beep
        --Insert your code here
    end if
end if

EDIT

 set handPath to "/Volumes/Flash Drive/HandBrakeCLI"
set dest_folder to POSIX path of dest_folder
if text -1 of dest_folder ≠ "/" then set dest_folder to dest_folder & "/"
set newFilepathPOSIX to dest_folder & "video.mp4"

tell application "System Events" to exists newFilepathPOSIX
if the result then
    display dialog "There is already a file named \"video.mp4\". Do you want to replace the file?" buttons {"Quit", "No", "Yes"} cancel button 1
    if button returned of the result = "No" then set newFilepathPOSIX to dest_folder & "video" & getDateAsString(current date) & ".mp4"
end if

set shellCommand to quoted form of handPath & " -i " & quoted form of origFilepathPOSIX & " -o " & quoted form of newFilepathPOSIX & " --preset=\"Classic\""
do shell script shellCommand

on getDateAsString(myDate)
    set creationDateString to year of myDate as string
    set creationDateString to creationDateString & text -2 thru -1 of ("0" & (month of myDate as integer) as text)
    set creationDateString to creationDateString & text -2 thru -1 of ("0" & day of myDate as text)
    set creationDateString to creationDateString & text -2 thru -1 of ("0" & hours of myDate as text)
    set creationDateString to creationDateString & text -2 thru -1 of ("0" & minutes of myDate as text)
    set creationDateString to creationDateString & text -2 thru -1 of ("0" & seconds of myDate as text)
end getDateAsString