Skip to content

Instantly share code, notes, and snippets.

@zoomlogo
Last active October 26, 2024 16:21
Show Gist options
  • Save zoomlogo/396fc31bac44665a1bfdd6eb54c8d5c2 to your computer and use it in GitHub Desktop.
Save zoomlogo/396fc31bac44665a1bfdd6eb54c8d5c2 to your computer and use it in GitHub Desktop.
simple script to compare directories
#!/usr/bin/python
# compare two directories
import os
import sys; sys.argv = sys.argv[1:]
from colorama import Fore, Style
if len(sys.argv) == 1 and ("help" in sys.argv or "h" in sys.argv):
print("usage: compare <old_dir> <new_dir>")
sys.exit(0)
if len(sys.argv) != 2:
print("error: too few/much arguments provided. expected 2.", file=sys.stderr)
sys.exit(1)
files = []
for directory in sys.argv:
try:
files.append(os.listdir(directory))
except FileNotFoundError:
print(f"error: {directory} not found.", file=sys.stderr)
sys.exit(1)
files1 = files[0]
files2 = files[1]
# new files
print(end=Fore.GREEN)
for file in files2:
if file not in files1:
print(f"+ {file}")
print(end=Style.RESET_ALL)
# old files
print(end=Fore.RED)
for file in files1:
if file not in files2:
print(f"- {file}")
print(end=Style.RESET_ALL)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment