Comparing Folders
 Leave feedback
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.
- Instantiate the CompareOptions object.
 - Call the 
setDirectoryComparemethod to set theDirectoryCompareproperty totrue. - If needed, call the 
setFolderComparisonExtensionmethod to change the output format toHTML. By default the format isTXT. - If needed, call the
setShowOnlyChangedmethod totrueto display only changed items. - Initialize the Comparer object. Specify the path to the first compared folder and the 
CompareOptionsobject. - Call the add method of the Comparer object. Specify a path to the second folder and the 
CompareOptionsobject. - 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:
// ...
import com.groupdocs.comparison.Comparer;
import com.groupdocs.comparison.options.CompareOptions;
CompareOptions compareOptions = new CompareOptions();
compareOptions.setDirectoryCompare(true);
try (Comparer comparer = new Comparer("C:\\SourceFolder\\", compareOptions)) {
    comparer.add("C:\\TargetFolder\\", compareOptions);
    comparer.compare("C:\\result.html", compareOptions);
}
The following images show the comparison result:
| Result in HTML | Result in TXT | 
|---|---|
![]()  | ![]()  | 
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.

