ZTree.com  | ZEN  | About...  

 Index   Back

[Help!] help with tfc   [Help!]

By: Ben Kent       
Date: Oct 16,2021 at 09:01
In Response to: [Help!] help with tfc (David Wall)

> 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

624 views      
Thread locked
 

Messages in this Thread

 
96,637 Postings in 12,231 Threads, 350 registered users, 56 users online (0 registered, 56 guests)
Index | Admin contact |   Forum Time: Mar 28, 2024 - 10:42 am UTC  |  Hits:62,363,507  (15,904 Today )
RSS Feed