Articles

Solved Batch 'and', 'or', ect help

May 30, 2010 at 11:20:39
Specs: Windows XP

Is there 'and', 'or', etc. functions in Batch files? and if so can i have a list of all you know?

See More: Batch and, or, ect help

Report •


#1
May 30, 2010 at 19:36:54

Extract from http://ss64.com/nt/set.html

Arithmetic expressions (SET /a)

The expression to be evaluated can include the following operators:

AND &
OR |
XOR ^
LSH <<
RSH >>
Multiply Variable *=
Divide Variable /=
Add Variable +=
Subtract Variable -=
AND Variable &=
OR Variable |=
XOR Variable ^=
LSH Variable <<=
RSH Variable >>=


Report •

#2
May 30, 2010 at 19:37:15
✔ Best Answer

No, you have to use other means to achieve the equivalent.
You can stack, or nest ifs to get an AND effect:
if exist test2 if exist test1 echo Both
if A gtr B (
if C lss D (
if exist H echo Yes
))
and by using NOT you can effectively test the "OR":
if not exist test2 if not exist test1 echo Both NOT
(but that doesn't prove that neither one exists,
only that both of them don't)
There's lots of tricks for getting by without AND/OR of course.
(oops, wahine is right, logical/mathematical AND and OR are supported, just not the
conditional-compounding type.)

Report •

#3
May 31, 2010 at 01:25:39

What about && and ||, they rely on a return code but are close to AND and OR.

&& = If the return code from the command to the left is 0 execute the command to the right.

echo hello | find "ell" && echo ftw

|| = If the return code from the command to the left is grerater than 0 execute the command to the right.

echo hello | find "goodbye" || echo NOOOOOOO!

The only problem is that they can't be used to compound if statements, it's strictly:

command [ &&   |   || ] command [ ... ]


Report •

Related Solutions


Ask Question