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. Set the DirectoryCompare property to true.
  3. If needed, set the setFolderComparisonExtension property to change the output format to HTML. By default the format is TXT.
  4. If needed, set theShowOnlyChanged property 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 SourceFolder and TargetFolder folders:

using System;
using GroupDocs.Comparison;
using GroupDocs.Comparison.Options;
class YoursProgram
{
    static void Main(string[] args)
    {
        CompareOptions compareOptions = new CompareOptions
        {
            DirectoryCompare = true,
        };
        Comparer comparer = new Comparer("C:\\SourceFolder", compareOptions);
        comparer.Add("C:\\TargetFolder", compareOptions);
        comparer.Compare("C:\\Folder_to_save_result\\", compareOptions);
    }
}

The following images show the comparison result:

Result in HTMLResult in TXT

On this page