check prefix update

This commit is contained in:
Julian Freeman
2025-08-25 11:41:42 -04:00
parent 2237337571
commit 74ad981d98

View File

@@ -1,5 +1,26 @@
import os
import datetime
from collections import defaultdict
def build_tree(paths):
"""将相对路径列表转换为树形字典"""
tree = lambda: defaultdict(tree)
root = tree()
for path in paths:
parts = path.split(os.sep)
current = root
for part in parts:
current = current[part]
return root
def print_tree(d, indent=""):
"""递归打印树结构"""
last_key = list(d.keys())[-1] if d else None
for i, key in enumerate(d):
connector = "└── " if key == last_key else "├── "
print(indent + connector + key)
new_indent = indent + (" " if key == last_key else "")
print_tree(d[key], new_indent)
def main():
# 输入目录
@@ -22,13 +43,15 @@ def main():
for root, _, files in os.walk(dir_path):
for f in files:
if not f.startswith(prefix):
not_matching_files.append(os.path.join(root, f))
full_path = os.path.join(root, f)
rel_path = os.path.relpath(full_path, dir_path) # 相对路径
not_matching_files.append(rel_path)
# 输出结果
if not_matching_files:
print("以下文件不符合命名前缀要求:\n")
for file in not_matching_files:
print(file)
tree = build_tree(not_matching_files)
print_tree(tree)
else:
print("✅ 所有文件名都符合前缀要求。")