import os import hashlib import shutil TARGET_DIR = os.path.abspath("assets/slike/glavna_referenca") SAMPLE_DIR = os.path.abspath("_TRASH_SAMPLES") TRASH_DIR = os.path.abspath("_TRASH_BIN/targeted_cleanup") def get_file_hash(filepath): hasher = hashlib.md5() try: with open(filepath, 'rb') as f: buf = f.read(65536) while len(buf) > 0: hasher.update(buf) buf = f.read(65536) return hasher.hexdigest() except: return None def main(): if not os.path.exists(SAMPLE_DIR): print("❌ Sample directory missing.") return if not os.path.exists(TRASH_DIR): os.makedirs(TRASH_DIR) # 1. Get hashes of samples print(f"🎯 analyzing samples in {SAMPLE_DIR}...") target_hashes = set() for f in os.listdir(SAMPLE_DIR): if f.startswith("."): continue h = get_file_hash(os.path.join(SAMPLE_DIR, f)) if h: target_hashes.add(h) print(f"🎯 Loaded {len(target_hashes)} unique target signatures.") # 2. Scan and destroy print(f"🔍 Scanning {TARGET_DIR} for matches...") count = 0 matches = 0 for root, dirs, files in os.walk(TARGET_DIR): for filename in files: if filename.startswith("."): continue filepath = os.path.join(root, filename) file_hash = get_file_hash(filepath) if file_hash in target_hashes: # MATCH FOUND! # print(f"💥 Destroying: {filename}") shutil.move(filepath, os.path.join(TRASH_DIR, filename)) matches += 1 count += 1 if count % 1000 == 0: print(f" Scanned {count} files...") print(f"✨ DONE! Removed {matches} matching files to {TRASH_DIR}") if __name__ == "__main__": main()