I suggest to use a batch file with following code where third parameter passed to the batch file is the name of the file without path:
Code: Select all
@echo off
setlocal EnableExtensions EnableDelayedExpansion
cd /D "%ProgramFiles%\IDM Computer Solutions\UltraCompare"
for /F %%I in ('uc.com -qc "<folder path 1>\%~3" "<folder path 2>\%~3"') do (
set "Result=%%I"
if "!Result:~0,4!" == "Diff" uc.com -a -t "<folder path 1>\%~3" "<folder path 2>\%~3" -o "<Dif Output folder path>\%~3"
)
endlocal
Windows command processor requires that the application to run by
FOR is specified without surrounding double quotes in this case with that command line which is the reason why the current working directory is switched to program files folder of UltraCompare. The command
ENDLOCAL restores the initial working directory.
English
uc.com is executed for a
quick binary comparison of the file in the two different directories. The result is just
Same or
Different for this comparison.
It would be fine if
uc.com would additionally on a quick binary comparison exit with return code 1 on different files and with exit code 0 only on identical files. But this is not the case and therefore usage of language independent
errorlevel for results evaluation is not possible as demonstrated below with using
fc.exe for the quick binary comparison.
Well, I could see on a test with an older version of UltraCompare (v15.10.0.20) that
uc.com does not really output just
Same or
Different, but appends an additional carriage return to this string. That's a problem because this lets a simple string comparison with below line always fail.
Code: Select all
if "%%I" == "Different" uc.com -a -t "<folder path 1>\%~3" "<folder path 2>\%~3" -o "<Dif Output folder path>\%~3"
The loop variable holds also the erroneous carriage return and the strings are for that reason never equal.
As a workaround for this specific
uc.com issue the result is assigned from the loop to an environment variable and compared are only the first 4 characters of the environment variable case-sensitive with the string
Diff.
In case of the two compared files are not binary equal a text comparison is made writing the differences into the output file.
This task could be also achieved with the following batch code using Windows standard console application
fc.exe for the quick binary comparison and UltraCompare only for producing the output on different files:
Code: Select all
@echo off
%SystemRoot%\System32\fc.exe /B "<folder path 1>\%~3" "<folder path 2>\%~3" >nul
if errorlevel 1 "%ProgramFiles%\IDM Computer Solutions\UltraCompare\uc.exe" -a -t "<folder path 1>\%~3" "<folder path 2>\%~3" -o "<Dif Output folder path>\%~3"
Both solutions can't be used if for text comparison some ignore options are enabled by default in configuration and therefore each text comparison is a smart comparison on which 2 text files being binary not equal can be nevertheless equal with taking the ignoring options into account.
In this case it would be really needed to run always a text comparison with producing an output file and using
FINDSTR to check if the output file contains the information that there are no differences and delete the output file in this case.
Code: Select all
@echo off
"%ProgramFiles%\IDM Computer Solutions\UltraCompare\uc.exe" -a -t "<folder path 1>\%~3" "<folder path 2>\%~3" -o "<Dif Output folder path>\%~3"
%SystemRoot%\System32\findstr.exe /M /L /C:"0 : 0 Line(s) diff" "<Dif Output folder path>\%~3" >nul
if not errorlevel 1 del "<Dif Output folder path>\%~3"
The string "
0 : 0 Line(s) diff" must be adapted according to used version of UltraCompare and configured format for results file.