import os import shutil base_path = r'E:\Wiki\2nd\10_Wiki' canned_phrases = [ "I'm now integrating", "Analyzing the", "I'm also incorporating", "I've expanded my view", "I'm currently noting", "I'm currently drafting", "I'm noting casino-like tactics" ] deleted_files = [] for root, dirs, files in os.walk(base_path): for f in files: if f.endswith('.md'): file_path = os.path.join(root, f) if len(file_path) > 240: continue try: if os.path.getsize(file_path) == 0: os.remove(file_path) deleted_files.append(file_path) continue with open(file_path, 'r', encoding='utf-8', errors='ignore') as f_obj: content = f_obj.read(1000) if any(phrase in content for phrase in canned_phrases): f_obj.close() # Explicitly close os.remove(file_path) deleted_files.append(file_path) except Exception as e: print(f"Error on {f}: {e}") print(f"Deleted {len(deleted_files)} canned files.")