Skip to content

Instantly share code, notes, and snippets.

@whtsky
Last active October 2, 2020 14:44
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 whtsky/fa2f4f432ad87f31b3aa077e7b33eba5 to your computer and use it in GitHub Desktop.
Save whtsky/fa2f4f432ad87f31b3aa077e7b33eba5 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import shutil
import sys
from pathlib import Path
def handle_path(path: Path):
subfolders = []
seen_sdrs = set()
seen_files = set()
for entry in path.iterdir():
if entry.is_dir():
if entry.suffix == ".sdr":
seen_sdrs.add(entry.stem)
else:
subfolders.append(entry)
else:
# is file
seen_files.add(entry.stem)
diff = seen_sdrs - seen_files
for sdr_to_remove in diff:
sdr_path = path / f"{sdr_to_remove}.sdr"
print("Remove: ", sdr_path)
shutil.rmtree(sdr_path)
for folder in subfolders:
handle_path(folder)
path = Path(sys.argv[1])
handle_path(path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment