Returns the MD5 or SHA1 hash value (checksum) of a file.
TrFile_GetFileHash ( switches ; sourcefile )
|switches||determines the behavior of the function|
|sourcefile||the path to the file of which you want the hash value, or container data|
Switches must be one of this:
|-MD5||use the MD5 algorithm to calculate the hash.|
|-SHA1||use the SHA-1 algorithm to calculate the hash.|
You can also add this switch below:
|-Colons||add colons between the result, for easy human reading|
Data type returned
the hash value, which is a text of 32 or 40 characters.
If the file does not exist or if an error occurs an error code will be returned, starting with $$. Returned error codes can be:
|$$-43||fnfErr||File or folder not found|
Troi File Plug-in 6.0
FileMaker Pro 16 to FileMaker Pro 2023
The function result is also called a message-digest. It provides an easy way to check if a file has not changed (by comparing it to a stored hash). Also you can use this hash to check if two files are identical.
Note: On macOS only the data fork of a file is considered. The resource fork of a file is ignored.
SHA-1 is considered more secure as it is a longer hash (160-bit).
Starting with v12.1: you can also use a container (or a variable with container data) as the source parameter, for example a JPEG in a container field
TrFile_GetFileHash ( "-SHA1" ; "C:\Test.txt" ) ]
This will return the SHA1 hash value which looks like this: “65c25a0c4ad167d9394298beaf93d0e630d2767a”
Set Variable [ $hash ; TrFile_GetFileHash ( "-MD5 -Colons" ; "filemac:/Mac HD/Users/Smith/report.txt" ) ]
This will set the variable $hash to the MD5 hash value of the file. The result will be formatted, for easier reading, with colons between each byte and looks similar to this:
Used in example file
Troi File Plug-in online help (overview)