Before I read your last post I wrote first this simple batch file for comparing the files stored in the list file with UltraCompare.
Code: Select all
@echo off
setlocal EnableDelayedExpansion
set "Directory=C:\Temp"
set "Extension=.txt"
rem Very simple and quick check if UltraCompare program files directory
rem is in PATH and if this is not the case, add it to local copy of PATH
rem at beginning as no other Windows standard console applications from
rem directory %SystemRoot%\System32 are required for this batch script.
if "%PATH:UltraCompare=%" == "%PATH%" set "PATH=%ProgramFiles%\IDM Computer Solutions\UltraCompare;%PATH%"
for /F "usebackq tokens=1,2" %%I in ("%Directory%\ListFile.txt") do (
for /F %%# in ('uc.com -qc "%Directory%\%%I%Extension%" "%Directory%\%%J%Extension%"') do set "Result=%%#"
if "!Result:~0,4!" == "Diff" uc.com -B -ne -t "%Directory%\%%I%Extension%" "%Directory%\%%J%Extension%" -o "%Directory%\%%I_Compared_UC%Extension%"
)
endlocal
Note: The string values assigned to the environment variables
Directory and
Extension might be modified as well as path to program files folder of UltraCompare and path and name of the list file
ListFile.txt.
And I wrote also an UltraEdit scripting solution for this file comparison task only poorly tested.
Code: Select all
if (UltraEdit.document.length > 0) // Is any file opened?
{
var sLineTerm = "\r\n";
var sDirectory = "C:\\Temp\\";
var sExtension = ".txt";
// Define environment for this script.
UltraEdit.insertMode();
if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();
// Active file should be the least file with the file names.
UltraEdit.activeDocument.selectAll();
if (UltraEdit.activeDocument.isSel())
{
// Load the file name pairs into an array of strings.
var asFileNames = UltraEdit.activeDocument.selection.split(sLineTerm);
// Remove the last string if it is an empty string because
// the list file ends with a DOS/Windows line termination.
if (!asFileNames[asFileNames.length-1].length) asFileNames.pop();
// Cancel the selection in list file kept open although not further used.
UltraEdit.activeDocument.top();
// Run the next loop for each file name pair.
for (nFileNameIndex = 0; nFileNameIndex < asFileNames.length; nFileNameIndex++)
{
// Get position of tab character seperating the two file names.
var nTabPos = asFileNames[nFileNameIndex].indexOf("\t");
if (nTabPos < 0) continue; // Skip this line if there is no tab.
// Get the two file names.
var sFileNameLeft = asFileNames[nFileNameIndex].substr(0,nTabPos) + sExtension;
var sFileNameRight = asFileNames[nFileNameIndex].substr(nTabPos+1) + sExtension;
// Load all lines from left file.
UltraEdit.open(sDirectory+sFileNameLeft);
UltraEdit.activeDocument.selectAll();
var asLinesLeft = UltraEdit.activeDocument.selection.split(sLineTerm);
UltraEdit.closeFile(UltraEdit.activeDocument.path,2);
// Load all lines from right file.
UltraEdit.open(sDirectory+sFileNameRight);
UltraEdit.activeDocument.selectAll();
var asLinesRight = UltraEdit.activeDocument.selection.split(sLineTerm);
UltraEdit.closeFile(UltraEdit.activeDocument.path,2);
// Remove from lines of right file all non empty lines also in left file.
var nLineIndexLeft;
var nLineIndexRight;
for (nLineIndexLeft = 0; nLineIndexLeft < asLinesLeft.length; nLineIndexLeft++)
{
if (!asLinesLeft[nLineIndexLeft].length) continue;
for (nLineIndexRight = 0; nLineIndexRight < asLinesRight.length; nLineIndexRight++)
{
if (asLinesRight[nLineIndexRight] == asLinesLeft[nLineIndexLeft])
{
asLinesRight[nLineIndexRight] = "#";
asLinesLeft[nLineIndexLeft] = "#";
break;
}
}
}
nLineIndexLeft = 0;
nLineIndexRight = 0;
var sLineLeft = "";
var sLineRight = "";
var sDifferences = "";
var bNewDiffBlock = false;
while ((nLineIndexLeft < asLinesLeft.length) || (nLineIndexRight < asLinesRight.length))
{
while (nLineIndexLeft < asLinesLeft.length)
{
if (!asLinesLeft[nLineIndexLeft].length)
{
nLineIndexLeft++;
}
else
{
if (asLinesLeft[nLineIndexLeft] != "#")
{
sLineLeft = "File L " + "line " + (nLineIndexLeft+1).toString(10) +
" = " + asLinesLeft[nLineIndexLeft] + sLineTerm;
}
break;
}
}
while (nLineIndexRight < asLinesRight.length)
{
if (!asLinesRight[nLineIndexRight].length)
{
nLineIndexRight++;
}
else
{
if (asLinesRight[nLineIndexRight] != "#")
{
sLineRight = "File R " + "line " + (nLineIndexRight+1).toString(10) +
" = " + asLinesRight[nLineIndexRight] + sLineTerm;
}
break;
}
}
// Are there in both files different lines?
if (sLineLeft.length && sLineRight.length)
{
sDifferences += sLineTerm + "* " + sLineLeft + "* " + sLineRight;
sLineLeft = "";
sLineRight = "";
nLineIndexLeft++;
nLineIndexRight++;
bNewDiffBlock = true;
}
// Are there in both files identical lines?
else if (!sLineLeft.length && !sLineRight.length)
{
nLineIndexLeft++;
nLineIndexRight++;
bNewDiffBlock = true;
}
else // There are only in one file lines not existing in other file.
{
if (bNewDiffBlock)
{
bNewDiffBlock = false;
sDifferences += sLineTerm;
}
if (sLineLeft.length) // Does the line exist only in left file?
{
sDifferences += "<! " + sLineLeft;
sLineLeft = "";
nLineIndexLeft++;
}
else // The line exists only in right file?
{
sDifferences += "!> " + sLineRight;
sLineRight = "";
nLineIndexRight++;
}
}
}
if (sDifferences.length)
{
// A new file is created for the difference output.
UltraEdit.newFile();
UltraEdit.activeDocument.unixMacToDos();
UltraEdit.activeDocument.write("File L: " + sDirectory + sFileNameLeft + sLineTerm);
UltraEdit.activeDocument.write("File R: " + sDirectory + sFileNameRight + sLineTerm);
UltraEdit.activeDocument.write(sLineTerm + "Differences:" + sLineTerm);
UltraEdit.activeDocument.write(sDifferences);
UltraEdit.saveAs(sDirectory+sFileNameLeft.replace(sExtension,"_Compared_UE"+sExtension));
UltraEdit.closeFile(UltraEdit.activeDocument.path,2);
sDifferences = "";
}
}
}
}
Note: The string values assigned to the JavaScript string variables
sDirectory and
sExtension might be modified. The list file must be the active file on script execution.
The batch script as well as the UltraEdit script expect both a list file containing per line two file names without file extension separated by a single tab character and not containing 1 or more spaces in any file name.
I did not know that you now wanted all different results in a single file instead of individual files with name depending on left file name. That would be of course also very easy to achieve by using in batch file
-op instead of
-o with always same file name like
"%Directory%\DiffResults%Extension%" and by writing all differences by the UltraEdit script into same new file created once at beginning instead of a new file for each file pair as it can be seen on script code below.
Code: Select all
if (UltraEdit.document.length > 0) // Is any file opened?
{
var sLineTerm = "\r\n";
var sDirectory = "C:\\Temp\\";
var sExtension = ".txt";
// Define environment for this script.
UltraEdit.insertMode();
if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();
// Active file should be the least file with the file names.
UltraEdit.activeDocument.selectAll();
if (UltraEdit.activeDocument.isSel())
{
// Load the file name pairs into an array of strings.
var asFileNames = UltraEdit.activeDocument.selection.split(sLineTerm);
// Remove the last string if it is an empty string because
// the list file ends with a DOS/Windows line termination.
if (!asFileNames[asFileNames.length-1].length) asFileNames.pop();
// Cancel the selection in list file kept open although not further used.
UltraEdit.activeDocument.top();
var nResultsFileIndex = UltraEdit.document.length
UltraEdit.newFile();
var oResultsFile = UltraEdit.document[nResultsFileIndex];
UltraEdit.activeDocument.unixMacToDos();
// Run the next loop for each file name pair.
for (nFileNameIndex = 0; nFileNameIndex < asFileNames.length; nFileNameIndex++)
{
// Get position of tab character seperating the two file names.
var nTabPos = asFileNames[nFileNameIndex].indexOf("\t");
if (nTabPos < 0) continue; // Skip this line if there is no tab.
// Get the two file names.
var sFileNameLeft = asFileNames[nFileNameIndex].substr(0,nTabPos) + sExtension;
var sFileNameRight = asFileNames[nFileNameIndex].substr(nTabPos+1) + sExtension;
// Load all lines from left file.
UltraEdit.open(sDirectory+sFileNameLeft);
UltraEdit.activeDocument.selectAll();
var asLinesLeft = UltraEdit.activeDocument.selection.split(sLineTerm);
UltraEdit.closeFile(UltraEdit.activeDocument.path,2);
// Load all lines from right file.
UltraEdit.open(sDirectory+sFileNameRight);
UltraEdit.activeDocument.selectAll();
var asLinesRight = UltraEdit.activeDocument.selection.split(sLineTerm);
UltraEdit.closeFile(UltraEdit.activeDocument.path,2);
// Remove from lines of right file all non empty lines also in left file.
var nLineIndexLeft;
var nLineIndexRight;
for (nLineIndexLeft = 0; nLineIndexLeft < asLinesLeft.length; nLineIndexLeft++)
{
if (!asLinesLeft[nLineIndexLeft].length) continue;
for (nLineIndexRight = 0; nLineIndexRight < asLinesRight.length; nLineIndexRight++)
{
if (asLinesRight[nLineIndexRight] == asLinesLeft[nLineIndexLeft])
{
asLinesRight[nLineIndexRight] = "#";
asLinesLeft[nLineIndexLeft] = "#";
break;
}
}
}
nLineIndexLeft = 0;
nLineIndexRight = 0;
var sLineLeft = "";
var sLineRight = "";
var sDifferences = "";
var bNewDiffBlock = false;
while ((nLineIndexLeft < asLinesLeft.length) || (nLineIndexRight < asLinesRight.length))
{
while (nLineIndexLeft < asLinesLeft.length)
{
if (!asLinesLeft[nLineIndexLeft].length)
{
nLineIndexLeft++;
}
else
{
if (asLinesLeft[nLineIndexLeft] != "#")
{
sLineLeft = "File L " + "line " + (nLineIndexLeft+1).toString(10) +
" = " + asLinesLeft[nLineIndexLeft] + sLineTerm;
}
break;
}
}
while (nLineIndexRight < asLinesRight.length)
{
if (!asLinesRight[nLineIndexRight].length)
{
nLineIndexRight++;
}
else
{
if (asLinesRight[nLineIndexRight] != "#")
{
sLineRight = "File R " + "line " + (nLineIndexRight+1).toString(10) +
" = " + asLinesRight[nLineIndexRight] + sLineTerm;
}
break;
}
}
// Are there in both files different lines?
if (sLineLeft.length && sLineRight.length)
{
sDifferences += sLineTerm + "* " + sLineLeft + "* " + sLineRight;
sLineLeft = "";
sLineRight = "";
nLineIndexLeft++;
nLineIndexRight++;
bNewDiffBlock = true;
}
// Are there in both files identical lines?
else if (!sLineLeft.length && !sLineRight.length)
{
nLineIndexLeft++;
nLineIndexRight++;
bNewDiffBlock = true;
}
else // There are only in one file lines not existing in other file.
{
if (bNewDiffBlock)
{
bNewDiffBlock = false;
sDifferences += sLineTerm;
}
if (sLineLeft.length) // Does the line exist only in left file?
{
sDifferences += "<! " + sLineLeft;
sLineLeft = "";
nLineIndexLeft++;
}
else // The line exists only in right file?
{
sDifferences += "!> " + sLineRight;
sLineRight = "";
nLineIndexRight++;
}
}
}
if (sDifferences.length)
{
if (oResultsFile.currentLineNum > 1)
{
oResultsFile.write(sLineTerm + "------------------------------------------------------------" + sLineTerm +sLineTerm);
}
oResultsFile.write("File L: " + sDirectory + sFileNameLeft + sLineTerm);
oResultsFile.write("File R: " + sDirectory + sFileNameRight + sLineTerm);
oResultsFile.write(sLineTerm + "Differences:" + sLineTerm);
oResultsFile.write(sDifferences);
sDifferences = "";
}
}
}
}