What is the simplest and/or most readable method to IF with AND in a CMD shell? In pseudo code:
IF EXIST file1 AND file2:
then do stuff
ELSE:
do something else
this Q has to be somewhere on SO but my search-fu isn’t working for this one. sorry
Assuming you are talking about DOS/Windows batch files, I think you want something like this:
The source of the ugliness is that DOS batch file
ifstatements do not have and and or operators, so you have to either write nestedifstatements (which can lead to duplicated code in the then and else clauses), or capture the expression result into a variable and then do anifstatement on its value (lots more lines). I favor the second approach to avoid duplication of code. Perhaps this is all a security feature. 🙂I found some good examples here and here (SO, even). But you can also just use the help system built into the shell (
help iforif /?IIRC).