It's easy to retrieve the size, datetime stamp of a file or folder, and then compare the result with another file.
But I don't found an instruction like this ..: FileCompare ...
Is it difficult to compare the binary content of two files with AHK?
Will the solution be slow?
Compare binaryfiles with AHK
Re: Compare binaryfiles with AHK
Calculate a hash of a file crc32, md5 demo with Gui https://github.com/jNizM/HashCalc although I believe https://github.com/jNizM/AHK_CNG is the 'latest' code by jNizM (check the hash functions)
Re: Compare binaryfiles with AHK
This is the function that I use currently:
conversion logic, v1 = -> v1 := -> v2, two-way compatibility - Page 5 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 80#p169780
The problem with the function above is that it loads the file into memory before comparing, I don't know if there's a better approach that operates on files directly.
Code: Select all
JEE_FilesMatchContents(vPath1, vPath2)
{
FileGetSize, vSize1, % vPath1
FileGetSize, vSize2, % vPath2
if !(vSize1 = vSize2)
return 0
if (vSize1 = 0) && (vSize2 = 0)
return 1
;FileRead, vData1, % "*c " vPath1
;FileRead, vData2, % "*c " vPath2
oFile := FileOpen(vPath1, "r")
oFile.Pos := 0
oFile.RawRead(vData1, oFile.Length)
oFile.Close()
oFile := FileOpen(vPath2, "r")
oFile.Pos := 0
oFile.RawRead(vData2, oFile.Length)
oFile.Close()
return !DllCall("msvcrt\memcmp", Ptr,&vData1, Ptr,&vData2, UPtr,vSize1, "Cdecl Int")
}
Some related info:
https://autohotkey.com/boards/viewtopic ... 80#p169780
The problem with the function above is that it loads the file into memory before comparing, I don't know if there's a better approach that operates on files directly.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
-
- Posts: 16
- Joined: 17 Jul 2017, 16:55
Re: Compare binaryfiles with AHK
Here's a method from Christian Ghisler that takes 3 approaches.
1. Check file sizes
If identical,
2. Compare small pieces of the files
If identical,
3. Calculate MD5
Because this method is performing small spot checks rather than reading the entire file, it often detects differences very quickly.
Wiki http://www.ghisler.ch/wiki/index.php/Au ... le_compare
1. Check file sizes
If identical,
2. Compare small pieces of the files
If identical,
3. Calculate MD5
Because this method is performing small spot checks rather than reading the entire file, it often detects differences very quickly.
Wiki http://www.ghisler.ch/wiki/index.php/Au ... le_compare
Re: Compare binaryfiles with AHK
For comparing two files, jeeswg's function is the best suggestion here imo. There is no point in calculating hashes in this case. In case of very big files I'd avoid reading the entire file unconditionally. You could loop chunks of 50-500 mb perhaps. One could even start at a small size and then increase. If you want to compare many files against each other, hash is good.
Cheers.
Cheers.
Who is online
Users browsing this forum: filipemb and 155 guests