1

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?

4

1 に答える 1

2

2 つのファイルを作成しました。

x.txt (7 バイト)

abcdefg

y.txt (16 バイト)

abcdefg
hijklmn

を使用して比較すると、オプションは違いをバイトごとに表示する/bため、違いは報告されませんでした。/bより小さいファイルの最後に到達すると、比較を停止します。このテストでは、最初の 7 バイトのみを比較し、y.txt が x.txt より長いと報告しました。

あなたの 2 つのファイルは、小さい方のファイルの末尾と同一であると推測しています。そのため、違いは報告されませんでした。私のテストケースでは、報告されませんでしno differences encounteredた。おそらくそれは、別の OS で実行していて、バグを発見した可能性が高いためですFC.EXE... 私は WinSvr2008R2 を使用しています。ver私のためにDOSレポートから実行しMicrosoft Windows [Version 6.1.7601]ています。のファイルの詳細は次のFCとおりです。

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

Windows エクスプローラーで詳細を表示すると、次のように表示されます。

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

.

2013 年 1 月 28 日編集

バイナリ比較を行っているため、ファイルが異なるかどうかを確認するためだけに、大きなバイナリ diff ファイルを生成せずに実行できます。Microsoft File Checksum Integrity Verifierfciv.exeをダウンロードし、 がパスのどこかにあることを確認すると、次のバッチ ファイルを記述して、2 つのファイルが同じか異なるかを判断できます。

@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
于 2013-01-24T06:20:02.830 に答える