Compare Folders

GroupDocs.Comparison for Python via .NET can compare two folders, surface which files were added, deleted, or modified, and produce either a TXT or HTML report.

Steps:

  1. Instantiate CompareOptions.
  2. Set directory_compare = True.
  3. Optionally set folder_comparison_extension to FolderComparisonExtension.HTML for an HTML report (the default is TXT).
  4. Optionally set show_only_changed = True to filter out unchanged items.
  5. Create Comparer with the source folder path and the CompareOptions.
  6. Call add() with the target folder and the same CompareOptions.
  7. Call compare_directory() with the result file path and the CompareOptions.

Example: Compare two folders

The example below uses the bare folder names SourceFolder and TargetFolder rather than ./SourceFolder so that the example-runner can detect them as shared sample directories. In your own code you can use any absolute or relative path — ./source-folder, /home/me/projects/src, etc.

from groupdocs.comparison import Comparer
from groupdocs.comparison.options import CompareOptions, FolderComparisonExtension

def compare_folders():
    compare_options = CompareOptions()
    compare_options.directory_compare = True
    compare_options.folder_comparison_extension = FolderComparisonExtension.HTML
    compare_options.show_only_changed = True

    with Comparer("SourceFolder", compare_options) as comparer:
        comparer.add("TargetFolder", compare_options)
        comparer.compare_directory("./result.html", compare_options)
        print("Folders compared successfully. Check output in result.html.")

if __name__ == "__main__":
    compare_folders()
<!DOCTYPE html><style>
details {
   padding-left: 20px;
}
details details 
   padding-left: calc(100 % -20px);
}
details summary {
    padding-left: 20px;
    cursor: pointer;
[TRUNCATED]

Download full output

Replace ./SourceFolder and ./TargetFolder with the directories you want to compare.

The following images show the comparison results:

Result in HTMLResult in TXT
Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.