Skip to content

Instantly share code, notes, and snippets.

@chapmanjacobd
Created December 3, 2023 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chapmanjacobd/e50991d249727e104894716bcbac9129 to your computer and use it in GitHub Desktop.
Save chapmanjacobd/e50991d249727e104894716bcbac9129 to your computer and use it in GitHub Desktop.
def compare_stats(destination_files, destination_folders, source_files, source_empty_folders):
new_empty_folders = source_empty_folders - destination_folders
source_dirs = {p.parent for p in source_files}
destination_dirs = {p.parent for p in destination_files}
new_directories = source_dirs - destination_dirs
new_files = source_files - destination_files
replaced_files = source_files & destination_files
trumped_files = replaced_files.intersection(source_files | destination_files)
return (
new_empty_folders,
new_directories,
new_files,
replaced_files,
trumped_files
)
source_at_dest_files = set()
source_at_dest_empty_folders = set()
for source in args.sources:
source_folder, source_glob = split_folder_glob(source)
source_files, source_empty_folders = existing_stats(source_folder, source_glob)
source_at_dest_files.update(source_files)
source_at_dest_empty_folders.update(source_empty_folders)
stats = compare_stats(destination_files, destination_empty_folders, source_files, source_empty_folders)
new_empty_folders, new_directories, new_files, replaced_files, trumped_files = stats
print(f"New empty folders: {len(new_empty_folders)}")
print(f"New directories: {len(new_directories)}")
print(f"New files: {len(new_files)}")
print(f"Replaced files: {len(replaced_files)}")
print(f"trumped files: {len(trumped_files)}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment