Comparing Folders

On this page

GroupDocs.Comparison allows you to compare the contents of a folder (directory), process and save the result of processing. The steps for starting the comparison and configuring the display of the processing result in the resulting file are described below.

  1. Instantiate the CompareOptions object.
  2. Call the setDirectoryCompare method to set the DirectoryCompare property to true.
  3. If needed, call the setFolderComparisonExtension method to change the output format to HTML. By default, the format is TXT.
  4. If needed, call the setShowOnlyChanged method to true to display only changed items.
  5. Initialize the Comparer object. Specify the path to the first compared folder and the CompareOptions object.
  6. Call the add() method of the Comparer object. Specify a path to the second folder and the CompareOptions object.
  7. Call the compare() method of the Comparer object. Specify a path to save the compare results and the CompareOptions object.

The following code snippet shows how to compare the folder1 and folder2 folders:

const compareOptions = new groupdocs.comparison.CompareOptions();
compareOptions.setDirectoryCompare(true);
const comparer = new groupdocs.comparison.Comparer("C:\\folder1\\", compareOptions);
comparer.add("C:\\folder2\\", compareOptions);
comparer.compare("C:\\res.html", compareOptions);

The following images show the comparison result:

Result in HTMLResult in TXT

On this page