CrazyCoder
CrazyCoder

Reputation: 780

Why does comparing two files using FC.exe with /b option produce different results between manual and batch execution?

I try to compare two files byte by byte using fc.exe with option /b for a binary compare.

When I run the command from within a command prompt window, the output lists the binary differences.

For example the command:

C:\Work\jan21\script>fc.exe /b C:\abc\2.0\common.c C:\Users\rakeshk\Desktop\download_break\final\common.c >b.txt

results in b.txt containing:

Comparing files C:\ABC\2.0\common.c and C:\USERS\RAKESHK\DESKTOP\DOWNLOAD_BREAK\FINAL\COMMON.C
00000994: 20 09
00000995: 20 69
00000996: 49 6E
00000997: 4E 74
00000998: 20 0D
00000999: 20 0A
0000099A: 55 20
...

And at end FC printed:

C:\USERS\RAKESHK\DESKTOP\DOWNLOAD_BREAK\FINAL\COMMON.C longer than C:\ABC\2.0\common.c

But when I run in batch file for example this command line

fc.exe /b !FILE1! !FILE2!>c.txt

the file c.txt contains

Comparing files C:\USERS\RAKESHK\DESKTOP\DOWNLOAD_BREAK\FINAL\COMMON.C longer than C:\ABC\2.0\common.c
FC: no differences encountered

Why is FC printing that there are no differences encountered although the files have different contents?

Upvotes: 1

Views: 12503

Answers (1)

James L.
James L.

Reputation: 9481

I created two files:

x.txt (7 bytes)

abcdefg

y.txt (16 bytes)

abcdefg
hijklmn

When comparing using /b, it didn't report any differences because the /b option shows the differences byte-by-byte. Once it comes to the end of the smaller file, it stops comparing. In this test, it only compared the first 7 bytes, then it reported y.txt is longer than x.txt.

I'm guessing that your two files are identical to the end of the smaller file, which is why it didn't report any differences. In my test case, it did not report no differences encountered. Perhaps that is because you are running on a different OS and you likely found a bug in FC.EXE... I'm using WinSvr2008R2. Running ver from DOS reports Microsoft Windows [Version 6.1.7601] for me. The file details for FC are:

07/13/2009  06:14 PM            19,968 fc.exe

If I view the details via Windows Explorer, I see:

File Description  -  DOS 5 File Compare Utility
File Version      -  6.1.7600.16385

.

Edit Jan 28, 2013

Since you are doing a binary compare, just to see if the files are different, you can do it without generating a large binary diff file. If you download the Microsoft File Checksum Integrity Verifier and ensure the fciv.exe is somewhere in your path, then you can write the following batch file to determine if two files are the same or different.

@echo off

setlocal ENABLEDELAYEDEXPANSION

for /f "skip=3 delims= " %%i in ('fciv -md5 %1') do set md5_1=%%i
for /f "skip=3 delims= " %%i in ('fciv -md5 %2') do set md5_2=%%i

if "!md5_1!"=="!md5_2!" (echo Files are the same) else (echo Files are different)

set md5_1=
set md5_2=

endlocal

Upvotes: 2

Related Questions