check prefix update
This commit is contained in:
@@ -1,5 +1,26 @@
|
|||||||
import os
|
import os
|
||||||
import datetime
|
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():
|
def main():
|
||||||
# 输入目录
|
# 输入目录
|
||||||
@@ -22,13 +43,15 @@ def main():
|
|||||||
for root, _, files in os.walk(dir_path):
|
for root, _, files in os.walk(dir_path):
|
||||||
for f in files:
|
for f in files:
|
||||||
if not f.startswith(prefix):
|
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:
|
if not_matching_files:
|
||||||
print("以下文件不符合命名前缀要求:\n")
|
print("以下文件不符合命名前缀要求:\n")
|
||||||
for file in not_matching_files:
|
tree = build_tree(not_matching_files)
|
||||||
print(file)
|
print_tree(tree)
|
||||||
else:
|
else:
|
||||||
print("✅ 所有文件名都符合前缀要求。")
|
print("✅ 所有文件名都符合前缀要求。")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user