Mostly Linux & Python syntax notes and hyperlinks.

Friday, February 19, 2010

DOS scripting: nesting if's in place of AND

I want to say 'IF EXIST file1 AND EXIST file2'... but there's no AND.

But I can nest the if EXIST's:
if EXIST file1 (if EXIST file2 echo Both There)
For the ELSE, it gets more complicated:
if EXIST file1 (if EXIST file2 (echo Both There) ELSE echo Nope)
 Will echo Nope if file1 exists and not file 2, but not if file2 exists but not file1.  So you need:
if EXIST file1 (if EXIST file2 (echo Both There) ELSE echo Not 2) ELSE echo Not 1
 That will tell you either "Both There", or "Not 1" if only file1 isn't, or "Not 2" if only file2 isn't.

No comments:

Post a Comment