Comparing Folders

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Comparison MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-comparison -- dnx GroupDocs.Comparison.Mcp --yes
Folders, licensing and more →

On this page

GroupDocs.Comparison allows you to compare the contents of a folder (directory), process and save the result of processing.

The following code snippet shows how to compare the two folders:

'use strict';

// Import the GroupDocs Comparison Node.js SDK
const groupdocs = require('@groupdocs/groupdocs.comparison');

// Create a CompareOptions instance to configure comparison settings
const compareOptions = new groupdocs.CompareOptions();

// Enable directory comparison mode
compareOptions.setDirectoryCompare(true);

// Initialize the Comparer with the source folder and the configured options
const comparer = new groupdocs.Comparer('sample-files/SourceFolder', compareOptions);

// Add the target folder to compare against
comparer.add('sample-files/TargetFolder', compareOptions);

// Run the comparison for directories and generate the result as an HTML file
comparer.compareDirectory('result.html', compareOptions);

// Terminate the process with a success exit code
process.exit(0);

This example creates a CompareOptions object and enables directory comparison mode by setting setDirectoryCompare(true). It initializes the Comparer with the source folder path and the options, adds the target folder using add() with the same options, and then calls compareDirectory() instead of compare() to perform folder comparison. The result is saved as an HTML file that shows which files were added, deleted, or modified between the two folders.

The following images show the comparison result:

Result in HTMLResult in TXT

On this page