DelphiFAQ Home Search:
General :: Programming :: Delphi
General Delphi related information.

Articles:

This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.
Recommended links on this topic:
Featured Article

Are 2 files identical? Do a 32bit CRC sum..

To determine, whether 2 files are identical, I first would compare their sizes.

If they are identical, I would calculate a 32bit CRC sum for each of them and compare the results.
It is extremely unlikely that the files are different but have the same CRC.

Someone asked me:
"Are you sure? Take for example two files, where the only difference would
be that in one of them, I turned a "hello" into a "ehllo". I guess the checksum
would be the same, don't you think?"

Answer: No, a CRC might even tell you where the difference was (if the files are really that short).
The following function does compute such a 32bit CRC (cyclic redundancy check) value:


     function ComputeFileCRC32(const FileName : string): LongInt;
 

Since the polynome table is rather long, you may download the pascal file: crc32.zip (2.2kB).
To compare, use something like this:

function Ident (const fn1, fn2 : string) : boolean;
 begin
   Ident := ComputeFileCRC32(fn1) = ComputeFileCRC32(fn2);
 end;
 

Generated 16:01:58 on Jun 22, 2018