So I have been trying to figure this out for a while, but nothing came to me. I have narrowed it down to a small case, so please let me know your thoughts.
I have a directory of files (1-a.txt and 1-b.txt) and a batch file like this:
for %%X in (1) do ^
fc %%X-a.txt %%X-b.txt > tmp.txt &^
if errorlevel 0 (echo 5) else (echo 6) &^
echo 7
Basically, I want it to echo 5 if the files are the same and 6, 7 if they are different.
However, it ALWAYS echos 5. Echo 7 is ignored entirely.
Any thoughts?
if errorlevelis true when the error level is at least 0. It’s always a greater than or equal comparison:Usually you can just switch the branches around:
In your case I’d also advise you to use parentheses to group statements:
As another option to the explicit
ifafter the program call there are also operators that run another command depending on the outcome of the previous one: