Last active
October 2, 2020 14:44
-
-
Save whtsky/fa2f4f432ad87f31b3aa077e7b33eba5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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