This repository has been archived on 2024-06-23. You can view files and clone it, but cannot push or open issues or pull requests.
mathdeptv2/工具v2/文件夹题号清点.py

17 lines
705 B
Python

rootpath = "d:/temp/dirtest" # 设置需要遍历的文件目录
from database_tools import *
texfiles, texpath = GetValidTexFiles(rootpath)
for path in texpath:
output_dict = {}
for texfile in [f for f in texfiles if f.startswith(path)]:
output_dict[os.path.split(texfile)[1]] = re.findall(r"\((\d{6})\)",ReadTextFile(texfile))
output = ""
for name in sorted(output_dict):
output += name + "\n"
output += "\n".join(output_dict[name])
output += "\n\n\n"
SaveTextFile(output,os.path.join(path,"题号清点.txt")) # 在每个有含题号的.tex文件所在的目录中生成 题号清点.txt
print("已完成文件夹 %s 中的题号清点"%path)