from pathlib import Path # Define your two lists of folders here FOLDERS_SET_1 = ["folder_11", "folder_12"] FOLDERS_SET_2 = ["folder_21", "folder_22"] def compare_folder_sets(set1_dirs, set2_dirs, out_missing_in_1, out_missing_in_2): files_set1 = set() files_set2 = set() # Gather all relative file paths from the first set of folders for folder in set1_dirs: root_path = Path(folder) for p in root_path.rglob('*'): if p.is_file(): files_set1.add(p.relative_to(root_path)) # Gather all relative file paths from the second set of folders for folder in set2_dirs: root_path = Path(folder) for p in root_path.rglob('*'): if p.is_file(): files_set2.add(p.relative_to(root_path)) # Find differences using set operations missing_in_1 = files_set2 - files_set1 missing_in_2 = files_set1 - files_set2 # Write missing files in the first set to a text file with open(out_missing_in_1, 'w', encoding='utf-8') as f: for path in sorted(missing_in_1): f.write(f"{path}\n") # Write missing files in the second set to another text file with open(out_missing_in_2, 'w', encoding='utf-8') as f: for path in sorted(missing_in_2): f.write(f"{path}\n") print("Comparison complete.") print(f"Missing in Set 1 saved to: {out_missing_in_1}") print(f"Missing in Set 2 saved to: {out_missing_in_2}") # --- Configuration --- compare_folder_sets( set1_dirs=FOLDERS_SET_1, set2_dirs=FOLDERS_SET_2, out_missing_in_1="missing_in_set_1.txt", out_missing_in_2="missing_in_set_2.txt" )