1

I have a clarification regarding Checksum of files.

In my test application, I got the same checksum value for a duplicated file of my original file. Also, when my original file was renamed, the checksum generated was same.

So, can I use the checksum to discard the processing of a duplicated file or a re-named file.

3 Answers 3

1

Yes, but you should use such checksum algorithm that can be used to generate fingerprints for your files. All checksums are not suitable for this.

0

Well, in general yes. It depends what sort of Checksum you're using though.

0

You should use the checksum to decide that you might skip processing of a file. Use a file compare to actually decide.

A checksum on a new file will match your original file, if their contents are the same. It will also match for other files that are not identical, because there are more possible file content strings than there are checksum values, no matter what checksum scheme you use. (You can make this pretty low probability but you can't make the problem go away).

So what you should do if file X (to be processed), has checksum C, the same as file A (already processed), is to compare the content of X with the content of A. If they are identical, you can use the answer for A as the answer for X. If you checksum scheme is at all decent, if X and A are NOT identical, you will find out after comparing just a few bytes. (You can even check the file sizes first but I doubt if this statistically saves you any time).

Of course, there's the problem of computing the checksum on X: that requires to read all the content of X. To compute it, you must read all of X. If generating the answer is cheap compared to doing disk reads, there isn't a lot of point to avoiding the work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.