> The line I'm currently using is as follows:
>
> tfc -o -b 02m 02w >nul & if %errorlevel% equ 0 (call>badd) else
> (call>gudd)
>
> If the two files 02m & 02w are either identical or different I'm
> getting the same result - which is a 0 byte file named badd, I never get
> one called gudd. ???
>
> Where am I going wrong ??.
That form will have %errorlevel% expanded at line read time and not at comparison time, and so will not give the expected result.
Some options
Go multi line, then %errorlevel% will be the expected value
------------
@echo off
tfc.exe -o -b 02m 02w >nul
if Not %errorlevel% == 1 (
call>badd
) else (
call>gudd
)
------------
You could use delayed expansion like this.
But then you cannot have filenames that include "!"
------------
@echo off
SetLocal EnableDelayedExpansion
tfc.exe -o -b 02m 02w >nul & if !errorlevel! equ 0 (call>badd) else (call>gudd)
------------
Switch to the "if Not errorlevel == 1 " form, which reads errorlevel at comparison time.
Note as "if errorlevel == 1" actually is greater or equal, so "if Not errorlevel == 1" is less than, so if you can assume no negative errorlevel's you can use it for equals zero.
------------
@echo off
tfc.exe -o -b 02m 02w >nul & if not errorlevel==1 (call>badd) else (call>gudd)
------------
But why not use Conditional Execution? see https://ss64.com/nt/syntax-conditional.html.
Plus I don't see what tfc.exe gives you in this use case over the standard fc.exe.
------------
@echo off
fc.exe /L 02m 02w >nul && (call>badd) || (call>gudd)
------------
Ben