Skip navigation

JSI Tip 10275. How can a batch script determine if there is a difference between two files?


I first described the FC.EXE command at tip 0305 » Windows NT 4.0 has two built in File comparison commands.

Using the built-in FC.EXE, I have scripted AnyDiff.bat to determine if there is any difference between two specified files.

The syntax for using AnyDiff.bat is:

Call AnyDiff File1 File2 YorN

Where:

File1 is the path to the first file.

File2 is the path to the second file.

YorN  is a call directed environment variable that will contain a
      Y if there any difference between the two files, or an N if there is no difference.
AnyDiff.bat contains:
@echo off
if \{%3\}==\{\} @echo Syntax: AnyDiff File1 File2 YorN&goto :EOF
if not exist %1 @echo AnyDiff %1 %2 %3 - %1 NOT found.&goto :EOF
if not exist %2 @echo AnyDiff %1 %2 %3 - %2 NOT found.&goto :EOF
fc /b %1 %2|find /i "no differences">nul
if errorlevel 1 (set %3=Y) ELSE (set %3=N)



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish