Archived

This topic is now archived and is closed to further replies.

How to compare two files?!

This topic is 5896 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I''m searching for an algorithm to compare two files, to find out which data has deleted, added, overwrote. If some one has an code snipped or an linkt to one, tips are welcome *g* Thanks alot... Mfg Impz0r

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
It depends on what you want to compare.
If you want to compare a char by char value in the file or compare the fields in the file.
For a field compare
Open both files
Parse both of the files and store in an object
Compare the objects.

This is not the fast way but it depends on how deep you want the compare to go. Need more info if you want a better answer

Share this post


Link to post
Share on other sites
Can''t you track down the source to the GNU diff program, which does exactly what you want(Or you could just use diff)? This is a good place to start searching.

"A society without religion is like a crazed psychopath without a loaded .45"

Share this post


Link to post
Share on other sites
Impressiv,

So many replays in this short time thanks a lot guys :D
Ok my main reason why i would compare two files is, i would make a patcher, i think you know what that is :D
And for this i have to find out which data has changed and find out if they deleted. If so, i havn''t store these data in the patch, else i store the changed data in the patch file. And there i run into problems, the main function to compare two files did i have. But i don''t know how to find out which data has deleted. Sory that i didn''t post these in my first post :D

Hope xou can help me out there :D

Mfg Impz0r

Share this post


Link to post
Share on other sites
How do patches work? Check it out.

MatrixCubed gave you the pseudocode algorithm for diff''ing two binary files (comparing by bytes). You''ll need to take care to ensure you recognize the difference between insertions (a new section of information) and modifications (overwriting the old info) - and both may occur in a file multiple times.

The GNU link Arild Fines gave you is also a good one; GNU has diff and patch utils (GNU patch works on binaries and text files) with freely available source code.

Finally, check these search results for information on diff and patch.

Share this post


Link to post
Share on other sites
y00,

Damn I''m back *g*, ok i got the GNU things, but i think these are a litle bit to complex for me. Hmmm, did some body know other Code snippets that can help me ?!

Thanks alot

Mfg Impz0r

Share this post


Link to post
Share on other sites
hmm,

Your right, thats true, hmmm but i think it must exists some other free patch code, if some here did know where i can find it pleas let me know :D

Mfg Impz0r

Share this post


Link to post
Share on other sites