I have made a template batch script that I can tell to carry out a function. I usually use it for pointing to files or locations, in this case, I want it to find and highlight a file and throw a custom error if the target isn't present. Whether the target is present or not, my script throws my error. What am I doing wrong or missing?
Here is my script:
SET TARGETPATH= "%TARGETPATH%"
IF NOT EXIST= "%TARGETPATH%" GOTO :ERROR
%SystemRoot%\explorer.exe /select, "%TARGETPATH%"
:END
:ERROR
SET msgboxTitle=%TITLE%
SET msgboxBody=%MESSAGE%
SET tmpmsgbox=%TEMP%\Message.vbs
IF EXIST "%tmpmsgbox%" DEL /F /Q "%tmpmsgbox%"
ECHO msgbox "%msgboxBody%",0,"%msgboxTitle%">"%tmpmsgbox%"
WSCRIPT "%tmpmsgbox%"
:END
I have moved and adjusted he position of line 3 (the target selector) to many different positions to prevent the error in a successful target acquisition. I have even set a :END
after the selector among many other things. How can I get this script to throw the error if, and only if the specified target isn't present?
goto END
; otherwise, after line 3 you will drop through into the error handling code.NOT EXIST
doesn't require=
at all, just use ` NOT EXIST "%TARGETPATH%"`goto END:
that I forgot to add in combination with @Máté Juhász's code correction. The script functions correctly now. If some one would like to provide the solution an answer, I will accept and upvote.