user1762109
user1762109

Reputation:

Looking for fast file comparison

My mission is to compare a list of hundreds of files in Windows. In each comparison I have to compare a pair of files. The files could be binaries or text files (all kinds)

I'm looking for the fastest time to run this. I have to check if the content is the same or not (I have nothing to do with the content itself - I have to report == or != ).

What could be the fastest way to do so? fc.exe? something else?

If fc.exe is the answer, are there any parameters that should accelerate response time?

I'd prefer to use an EXE that's part of standard Windows installation (but it's not a must).

THANK YOU

Upvotes: 2

Views: 3127

Answers (3)

Phil Mundy
Phil Mundy

Reputation: 11

@foxidrive answer has merit, especially when the files are big and on the same physical drive which, unless the comparing software slurps big file chunks at a time causes disk thrashing.

Two utils available are

Inbuilt (for windows 10 at least) C:\Windows\System32\certutil.exe This has a slightly awkward (enormous) parameter set but works well, does many more useful conversions and can use a large number of hash algorithms (sorry I lost the link to the full list of algorithms available ); it definitely works with sha1 sha256 sha384 md5. Ex. certutil -hashfile "E:\huge.7z" md5

and the Microsoft utility fciv (md5 generator by default) Google for "Microsoft File Checksum Integrity Verifier" and download from Microsoft Ex. fciv bigFile.7z

I know this is an old question, but I haven't seen these two utilities mentioned much... Hope it helps someone.

Upvotes: 0

dbenham
dbenham

Reputation: 130849

I'm assuming you want to do a binary comparison.

I would use the following to compare two files:

fc "file1" "file2" /b >nul && echo "file1" == "file2" || "file1" != "file2"

EDIT

If you have many very large files to compare, it may be worth while comparing file sizes before using FC to compare the entire file. I used the same indicator variable so that I could define the actions to take upon result of "same" or "different" just once, without resorting to CALLed subroutines. A CALL is relatively slow.

set "same="
for %%A in ("file1") do for %%B in ("file2") do (
  if %%~zA equ %%~zB fc %%A %%B /b >nul && set "same=1"
)
if defined same (
  echo "file1" == "file2"
) else (
  echo "file1" != "file2"
)

Upvotes: 2

foxidrive
foxidrive

Reputation: 41244

You can get a CRC hex string of each file using a third party command line tool and compare the hex strings.

Depending on how you are comparing sets of files, when using this method then each file only needs to be read once.

Upvotes: 0

Related Questions