chore: cleanup 0-byte md files, placeholders, and redundant nested directories in 10_Wiki

This commit is contained in:
2026-04-27 18:08:08 +09:00
parent 4e52a7c2b5
commit 975cadbb48
32 changed files with 101 additions and 810 deletions
+63
View File
@@ -0,0 +1,63 @@
import os
import shutil
base_path = r'E:\Wiki\2nd\10_Wiki'
placeholder_text = "I'm now integrating"
deleted_files = []
deleted_dirs = []
# 1. Delete nested directories
nested_dirs = [
os.path.join(base_path, '10_Wiki'),
os.path.join(base_path, '2nd')
]
for d in nested_dirs:
if os.path.exists(d):
try:
shutil.rmtree(d)
deleted_dirs.append(d)
except Exception as e:
print(f"Error deleting dir {d}: {e}")
# 2. Walk through files
for root, dirs, files in os.walk(base_path):
# Delete .obsidian folders found inside
if '.obsidian' in dirs:
obsidian_path = os.path.join(root, '.obsidian')
try:
shutil.rmtree(obsidian_path)
deleted_dirs.append(obsidian_path)
except Exception as e:
print(f"Error deleting .obsidian at {root}: {e}")
for f in files:
if f.endswith('.md'):
file_path = os.path.join(root, f)
# Skip the long path file (User requested to exclude item 4)
if len(file_path) > 240:
print(f"Skipping long path file: {f}")
continue
try:
# 0-byte check
if os.path.getsize(file_path) == 0:
os.remove(file_path)
deleted_files.append(file_path)
continue
# Placeholder content check
with open(file_path, 'r', encoding='utf-8', errors='ignore') as f_obj:
content = f_obj.read(500) # Check first 500 chars
if placeholder_text in content:
os.remove(file_path)
deleted_files.append(file_path)
except Exception as e:
print(f"Error processing file {f}: {e}")
print(f"Total files deleted: {len(deleted_files)}")
print(f"Total dirs deleted: {len(deleted_dirs)}")
for f in deleted_files[:10]:
print(f"Deleted: {os.path.basename(f)}")
+38
View File
@@ -0,0 +1,38 @@
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.")