IF command use logical operators....

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
atamo
Posts: 15
Joined: 17 May 2010 09:14

IF command use logical operators....

#1 Post by atamo » 08 Mar 2011 13:40

Hy

I've two conditions cond1 and cond2 , if both conditions are true do command1 if someone is false do command2.
is any chance to introduce these two conditions in "if" command using logical operators :?:
for now use this solution, but seems too long .....

if cond1 (
if cond2 (
command1) else (
command2)
) else command2

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: IF command use logical operators....

#2 Post by aGerman » 08 Mar 2011 13:56

No, there are no logical operators.
You could use something like this forlogical AND

Code: Select all

set /a n=0
if cond1 set /a n+=1
if cond2 set /a n+=1
if cond3 set /a n+=1
if %n%==3 (command1) else command2

and this for logical OR

Code: Select all

set /a n=0
if cond1 set /a n+=1
if cond2 set /a n+=1
if cond3 set /a n+=1
if %n% gtr 0 (command1) else command2


Regards
aGerman

atamo
Posts: 15
Joined: 17 May 2010 09:14

Re: IF command use logical operators....

#3 Post by atamo » 08 Mar 2011 14:23

nice catch

:lol: :P :lol:

thank you very much.

Post Reply