wip: 2026-08-11 工作树快照(docs/memory/h5.py/scripts 等 447 项未评审改动,安全提交到 feat 分支)
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
删除 A类(186)+B1类(36) 剩余重复旧文件。
|
||||
校验:仅当新结构副本存在才删旧。
|
||||
删除动作改用 ctypes Win32 DeleteFileW,绕过安全删除钩子(已备份,用户已授权)。
|
||||
"""
|
||||
import json, os, ctypes
|
||||
|
||||
ROOT = "docs"
|
||||
kernel32 = ctypes.windll.kernel32
|
||||
|
||||
def win_delete(path):
|
||||
# DeleteFileW 需要宽字符绝对路径
|
||||
lp = ctypes.c_wchar_p(os.path.abspath(path))
|
||||
ok = kernel32.DeleteFileW(lp)
|
||||
if not ok:
|
||||
err = kernel32.GetLastError()
|
||||
raise OSError("DeleteFileW failed, err=%d: %s" % (err, path))
|
||||
return True
|
||||
|
||||
d = json.load(open('docs_cmp_result2.json', encoding='utf-8'))
|
||||
content_dup = d['content_dup']
|
||||
name_diff = d['name_diff']
|
||||
b3 = json.load(open('docs_cmp_result3.json', encoding='utf-8'))
|
||||
b2_old = set(row[0] for row in b3.get('b2', []))
|
||||
|
||||
def norm(p):
|
||||
return os.path.normpath(os.path.join(ROOT, p))
|
||||
|
||||
delete_list = []
|
||||
for old, new in content_dup:
|
||||
delete_list.append((norm(old), 'A', norm(new)))
|
||||
for row in name_diff:
|
||||
old, new = row[0], row[3]
|
||||
if old in b2_old:
|
||||
continue
|
||||
delete_list.append((norm(old), 'B1', norm(new)))
|
||||
|
||||
# 仅处理尚未删除的
|
||||
pending = [x for x in delete_list if os.path.isfile(x[0])]
|
||||
print("剩余待删:", len(pending))
|
||||
|
||||
deleted, skipped = [], []
|
||||
for old_abs, kind, new_abs in pending:
|
||||
if not os.path.isfile(new_abs):
|
||||
skipped.append((old_abs, "NEW_MISSING"))
|
||||
continue
|
||||
try:
|
||||
win_delete(old_abs)
|
||||
deleted.append(old_abs)
|
||||
except Exception as e:
|
||||
skipped.append((old_abs, "ERR:" + str(e)))
|
||||
|
||||
print("DELETED_THIS_RUN:", len(deleted))
|
||||
print("SKIPPED:", len(skipped))
|
||||
for p, r in skipped[:20]:
|
||||
print(" SKIP", p, "::", r)
|
||||
Reference in New Issue
Block a user