Binary compare files
To achieve this we can use the command FC in DOS. Please consult the help of FC for more info on comparison options (FC /?).
- We’ll start with making the BAT file. Just copy the following text in a text file and rename it to COMPARE.CMD. Why do I use the CMD extension and not the BAT extension? More info here.
@echo off
FC /B %1 %2
IF %ERRORLEVEL%==0 EXIT 0
IF NOT %ERRORLEVEL%==0 EXIT 1
- The next step is creating the compare function in Dynamics Nav.
Name DataType Subtype Length lintWindowStyle integer lblnWait Boolean ltxtCommand Text 1024 lautShell Automation ‘Windows Script Host Object Model’.WshShell lintReturn Integer
fctCompare(ptxtFile1 : Text[200];ptxtFile2 : Text[200]) : Boolean
lintWindowStyle := 0; // needs to be placed in variable
lblnWait := TRUE; // needs to be placed in variable
ltxtCommand := ‘c:\compare.cmd “’+ ptxtFile1 +’” “’+ ptxtFile2+’”’;CLEAR(lautShell);
CREATE(lautShell);lintReturn := lautShell.Run(ltxtCommand,lintWindowStyle,lblnWait);
CASE lintReturn OF
0: EXIT(TRUE);
1: EXIT(FALSE);
END; - Call the function: fctCompare(’c:\test1.txt’,'c:\test\test2.txt’);
This will return TRUE if the files are identical and FALSE otherwise
Filed under: Automation, Dynamics NAV