Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: checksum md5 CRC12 CRC32 signature
;=================================================================== ;===== Function : F_GetFileChecksum ;===== Description : Retrieves a MD5, CRC16 or CRC32 from a file ;===== Release : 1.1 ;===== Programmer : TC ;===== Input : FileName : The file name without path ;===== Method = ;===== Specifies the type of digest or CRC to generate, and can be one of the following values: ;===== Return String Format (x=hex character) ;===== 0 = MD5 digest "xxxxxxxx-xxxxxxxx-xxxxxxxx-xxxxxxxx" ;===== 1 = 16-bit CRC "xxxx" ;===== 2 = 32-bit CRC "xxxxxxxx" ;===== verbose = @TRUE or verbose = @FALSE for messages ;===== Returns : Hex Value MD5,CRC16 or CRC32 or -1 when error, ;===== CATAGORY : ;===== STATUS : ;=================================================================== #DefineFunction F_GetFileChkSum(str_Filename, Method, Verbose) If Verbose Then Message (str_FileName,"%method% %verbose%") str_Currentdir = "nothing" int_FileSize = 0 int_BinBuf = 0 int_Info = 0 int_CheckForDir = 0 result = 0 str_CurrentDir = DirGet() ;0 = not found otherwise pos of substr int_CheckForDir = StrIndex(str_FileName, "\", 1, @FWDSCAN) ; Check if str_filename contains a path If int_CheckForDir == 0 str_FileName = StrCat(str_CurrentDir, str_FileName) ; Append the full path when no path is found EndIf If verbose Then Message("",str_filename) If FileExist(str_FileName) ; check if file exist int_FileSize = FileSize(str_FileName) int_BinBuf = BinaryAlloc(Int_FileSize+100) ; Allocate a buffer the size of your file + 100 bytes. If int_BinBuf == 0 If Verbose Then Message("Error", "BinaryAlloc Failed") Result = -1 Else BinaryRead(int_binbuf, str_FileName) ; Read the file into the buffer. str_info = BinaryChecksum(int_binbuf, method) If Verbose Then Message("test ",str_info) int_binbuf = BinaryFree(int_binbuf) Result = str_info EndIf Else Result = -1 EndIf Return Result #EndFunction ;=================================================================== ;===== End of function: F_GetFileChkSum(str_Filename, Method, Verbose) ;=================================================================== FileName = "f_getfilechksum.wbt" MD5digest = 0 CRC16 = 0 CRC32 = 0 ;verbose = @FALSE verbose = @TRUE MD5digest = F_GetFileChkSum(ileName,0,verbose) CRC16 = F_GetFileChkSum(FileName,1,verbose) CRC32 = F_GetFileChkSum(FileName,2,verbose) Message(FileName,"MD5=%MD5DIGEST%%@CRLF%CRC16=%CRC16%%@CRLF%CRC32=%CRC32%")
Article ID: W17476
File Created: 2008:04:10:15:11:22
Last Updated: 2008:04:10:15:11:22