1

I'm kinda newbie to CMD. I was wondering; is it possible to check for multiple criteria on different variables at once, using IF command? I mean, what would be the syntax of IF command if you wanted to check 2 different variables at the same time matching the given criteria? I mean does that thing exist? Something like:

IF %%variable1%% == variableone AND %variable2% == variabletwo do stuff

I've been trying to sort this out myself, but couldn't find a way to to doit. Kept getting errors. Maybe there's something wrong in the syntax of the command or I'm missing something.

iNT
  • 31
  • 3
  • possible duplicate of [Logical operators ("and", "or") in DOS batch](http://stackoverflow.com/questions/2143187/logical-operators-and-or-in-dos-batch) – sashoalm May 30 '15 at 05:07

2 Answers2

1

You cannot use logical operators, but you can do this:

IF %%variable1%% == variableone IF %variable2% == variabletwo GOTO :DOSTUFF

or

IF %%variable1%% == variableone (
  IF %variable2% == variabletwo (
    rem do stuff here
  )
)
pcnate
  • 1,694
  • 1
  • 18
  • 34
1

Another way to implement a logical AND:

if "%variable1%@%variable2%" == "variableone@variabletwo" goto :dostuff

Note1: @ is just a delimiter to get sure foo+bar and foob+ar are not treated the same. (foo@bar vs. foob@ar) Without a delimiter, both would give foobar.

Note2: the quotes prevent a syntax error when one side of the comparison is empty

Note3: I assume, %%variable1%% is a typing error and should read %variable1%

Stephan
  • 53,940
  • 10
  • 58
  • 91