Home > Software design >  How to use if else comparing string in a batch file?
How to use if else comparing string in a batch file?

Time:11-22

I would like to check the string is match or not. I tried this way, but it always return error, syntax error, I don't know which syntax that error. Error message

The syntax of the command is incorrect.

if TXT EQU TXT(

SET Format=TXT
REM ECHO %Format%

if %Format% EQU TXT(
ECHO Format correct
GOTO END
)

ECHO Format not correct

Anyone can help me please. Thank you so much

CodePudding user response:

This works for me:

@echo off
set format=TXT
if "%format%"=="TXT" (
@echo Format correct
goto :end
)
@echo Format not correct
:end
  • Related