check prefix
This commit is contained in:
36
check_prefix.py
Normal file
36
check_prefix.py
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
import os
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
def main():
|
||||||
|
# 输入目录
|
||||||
|
dir_path = input("请输入要检查的目录路径: ").strip()
|
||||||
|
if not os.path.isdir(dir_path):
|
||||||
|
print("输入的路径无效,请确认是一个目录。")
|
||||||
|
return
|
||||||
|
|
||||||
|
# 输入前缀
|
||||||
|
today = datetime.date.today().strftime("%Y%m%d")
|
||||||
|
pp = f"AI-{today}-"
|
||||||
|
prefix = input(f"请输入文件名前缀(留空则使用 {pp}): ").strip()
|
||||||
|
if not prefix:
|
||||||
|
prefix = pp
|
||||||
|
|
||||||
|
print(f"\n使用的前缀是: {prefix}\n")
|
||||||
|
|
||||||
|
# 遍历目录
|
||||||
|
not_matching_files = []
|
||||||
|
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))
|
||||||
|
|
||||||
|
# 输出结果
|
||||||
|
if not_matching_files:
|
||||||
|
print("以下文件不符合命名前缀要求:\n")
|
||||||
|
for file in not_matching_files:
|
||||||
|
print(file)
|
||||||
|
else:
|
||||||
|
print("✅ 所有文件名都符合前缀要求。")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Reference in New Issue
Block a user