Suppress FC: no differences encountered
fc.exe
does not operate silently, that is, unlike the Unix shell command
diff
, it explicitly prints
FC: no differences encountered even if the two compared files are equal.
However,
fc.exe
sets the exit value to 0 if the files are equal ant to 1 if they differ. Because the exit value can be queried through the variable
%errorlevel%
, this allows to write a
batch file which compares two files and remains silent if they're equal (by redirecting the output of
fc
to
nul
)
echo off
set file1=%1
set file2=%2
if "%file2%" == "" (echo diff.bat file-1 file-2 && exit /b)
if not exist "%file1%" (echo %file1% does not exist && exit /b)
if not exist "%file2%" (echo %file2% does not exist && exit /b)
fc.exe "%file1% "%file2%" > nul
if %errorlevel% neq 0 ( echo %file1% differs from %file2% )