When writing a batch script, DO loops are far superior to FOR loops. The
debugging ease alone is worth it.
FOR loops are by definition single line statements. So even if you broke
up the statement using command grouping, that only influences the
statement visually, not programatically.
Second, CMD.EXE has many anomalies with regard to how it processes
commands vs. how TCC does it. TCC has a "emulate CMD's aberrent behavior"
mode called "Duplicate CMD.EXE Bugs."
If "Duplicate CMD.EXE Bugs" is enabled (the default), the following
command will display nothing, because the second ECHO command is discarded
along with the first when the condition fails. If Duplicate CMD.EXE Bugs
is disabled, it will display "hello":
[c:\] if 1 == 2 echo Wrong! & echo hello
The original code that was posted was:
Code:
for /A:d %i in (*.*) do (
if exist %i\jetpdb\ (
del /FSEXY %i\jetpdb\
)
if exist %i\%i.exe (
del /F %i\%i.exe
)
)
That simplifies down to:
for %i in (*) do (if cond1 del A & if cond2 del B)
The CMD.EXE behavior states that if cond1 is false, the 2nd IF statement
will not be executed.
-Scott
thedave <> wrote on 11/06/2009 03:59:09 PM:
> I've bumped into this many times, I still prefer FOR loops out of habit
> although DO loops are preferred. Unfortunately I can't reproduce it on
> demand well enough to file a bug report.
>
> If you take the "for" loop out of the equation, or even just move the
> two "if" clauses into their own BTM and CALL it, then everything works.
>
> Whether or not the second IF will be tested may depend on the results of
> the first, it's almost like a failure on the first causes FOR loop to
> start on the next iteration.
>
> Switching to a DO loop instead of a FOR loop works around the problem,
> and/or you may have better luck with IFF instead of IF.
>
>