The trick to testing file contents is to do something like this:
( fc /B "%file1%" "%file2%" | find "FC: no differences encountered" ) > nul && ( echo "%file1%" and "%file2%" are the same ) || ( echo "%file1%" and "%file2%" are different )
using conditional execution.
Here is an example file using this trick in a separate “function”:
@echo off goto :main REM *** === Function "Compare" ================================================ :compare REM *** %1, %2 = the files if "%~2" == "" ( REM message to stderr echo error: missing argument 1>&2 ) else ( ( fc /B "%~1" "%~2" | find "FC: no differences encountered" ) > nul && ( echo "%~1" and "%~2" are the same ) || ( echo "%~1" and "%~2" are different ) ) goto :EOF REM *** === Main ============================================================== :main call :compare path\to\some\file path\to\another\file
Advertisements
Leave a Reply