<< Click to Display Table of Contents >> Navigation: 3. Script Language > Filesystem-Commands > FIL. - File-Commands > FIL. - File-Commands |
MiniRobotLanguage (MRL)
FIL.FileDiff
Compare two files including their content and return the Position of the first difference
Intention
This command is used to compare two files "Byte by Byte" for equality.
If both files are equal, the result is 1, otherwise the result is zero. On the TOS is the Position of the fist different Byte.
The command checks these files see error-codes below.
Usage of the command is simple:
' $$FIA - File 1
' $$FIA - File 2
' $$SPO - Starting Position in Byte starting at 1 .. File-Len
' $$RES - Variable mit Ergebnis
FIL.FileDiff|$$FIA|$$FIB|$$SPO|$$RES
if P3 is missing, default Starting Position is always 1
If P4 is missing, the result will be placed on the TOS.
Another Sample:
$$FOL=H:\Videotemp
$$ORI=$$FOL\Text a.txt
$$FIA=$$FOL\Text b.txt
FIL.FileDiff|$$ORI|$$FIA|-1|$$RES
VAN.$$DIF=$$000
FIL.Length|$$FIA|$$LEN
CAL.$$PLA=$$LEN-$$DIF+1
IVV.$$RES=0
DBP. Files are different at Reverse Position:$$DIF
DBP. Files are different at Position $$PLA
ELS.
DBP.Files are equal
EIF.
FIL.FileDiff|$$ORI|$$FIA||$$RES
IVV.$$RES=0
DBP. Files are different at: $$000
ELS.
DBP.Files are equal
EIF.
MBX.!
ENR.
File A is: AAAAAB
File B is: AAAACB
Output:
[16:35:51] Files are different at Reverse Position:2
[16:35:51] Files are different at Position 5
[16:35:51] Files are different at: 5
Possible Results:
1 - Files are Equal
If Files are not Equal, the Result is negative
-1 - can't compare Files or unequal size
-2 - File does not exist?, INVALID_FILE_ATTRIBUTES of File A-File
-3 - File does not exist?, INVALID_FILE_ATTRIBUTES of File B File
-4 - File A File is a Folder
-5 - File B is a Folder
-6 - Can't Open File A
-7 - Can't Open File B
-8 - reserved
-9 - Starting Position > Filesize
-10 - Error during Read
Syntax
FIL.FileDiff|P1|P2[|P3][|P4]
Parameter Explanation
P1 - Filename for file 1
P2 - Filename for file 2
P3 - (optional) Starting Byte Position for Compare (1 ... File-Length). if P3 is missing, default Starting Position is always 1
If P3 = -1 then the Search will start at the End of the File. The result will also be counted from the End of the file.
See Sample below.
P4 - (optional) Variable for the result. The result will be 0 or 1 or one of the Error-Code see above.
In case the files compute as identical, the result is 1.
If the files are computed as "non identical", the result is zero. If P4 is missing, the result will be placed on the TOS.
The Number of the first differing Byte is placed on TOS.
Example
'*****************************************************
' EXAMPLE 1: FIL.FileDiff
'*****************************************************
$$FOL=H:\Videotemp
$$ORI=$$FOL\TestA.mp4
$$FIA=$$FOL\TestA_injected A.mp4
FIL.FileDiff|$$ORI|$$FIA||$$RES
IVV.$$RES=0
DBP. Files are different at: $$000
ELS.
DBP.Files are equal
EIF.
ENR.
'-----------------------------------------------------------
'*****************************************************
' EXAMPLE 1: FIL.FileDiff
'*****************************************************
$$FOL=H:\Videotemp
$$ORI=$$FOL\Text a.txt
$$FIA=$$FOL\Text b.txt
FIL.FileDiff|$$ORI|$$FIA|-1|$$RES
VAN.$$DIF=$$000
FIL.Length|$$FIA|$$LEN
CAL.$$PLA=$$LEN-$$DIF+1
IVV.$$RES=0
DBP. Files are different at Reverse Position:$$DIF
DBP. Files are different at Position $$PLA
ELS.
DBP.Files are equal
EIF.
FIL.FileDiff|$$ORI|$$FIA||$$RES
IVV.$$RES=0
DBP. Files are different at: $$000
ELS.
DBP.Files are equal
EIF.
MBX.!
ENR.
Remarks
-
Limitations:
If both of the given Parameters evaluate to a folder that exists, the result is 1.
In this case there is no binary compare of the content.
This command does not compare folders. It should only be used on files.
See also:
• IEF. / NEF. - If - exist - File