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.
Set the directory_compare property of CompareOptions to true.
If needed, set the folder_comparison_extension to change the output format to HTML. By default, the format is TXT.
If needed, set the show_only_changed to true to display only changed items.
Initialize the Comparer object. Specify the path to the first compared folder and the CompareOptions object.
Call the add() method of the Comparer object. Specify a path to the second folder and the CompareOptions object.
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:
importgroupdocs.comparisonasgc# Set output_format as 'TXT' or 'HTML'defcompare_folders(output_format,output_file_name,SOURCE_FOLDER,TARGET_FOLDER):# Set compare options for directory comparisoncompare_options=gc.options.CompareOptions()compare_options.directory_compare=Truecompare_options.folder_comparison_extension=(gc.options.FolderComparisonExtension.HTMLifoutput_format=='HTML'elsegc.options.FolderComparisonExtension.TXT)# Create a new comparer with the source folder path and comparison optionscomparer=gc.Comparer(SOURCE_FOLDER,compare_options)# Add the target folder for comparisoncomparer.add(TARGET_FOLDER,compare_options)# Perform the comparison and save the resultcomparer.compare_directory(output_file_name,compare_options)print(f"\nFolders compared successfully.\nCheck output in {output_file_name}.")
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.