Files
file_renamer/check_prefix.py
Julian Freeman 2237337571 check prefix
2025-08-25 11:34:40 -04:00

37 lines
1020 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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()