import os from config.config import get_base_dir def get_template_files(): """ 遍历 templates 目录,返回所有 PPTX 文件的文件名列表 """ # 获取 templates 文件夹的绝对路径 # 这里的 get_base_dir() 是你之前定义的函数 base_dir = get_base_dir() templates_dir = os.path.join(base_dir, 'templates') # 检查目录是否存在,不存在则返回空列表 if not os.path.exists(templates_dir): return [] # 遍历目录 files = [] for filename in os.listdir(templates_dir): # 过滤掉隐藏文件,并只保留 .pptx 结尾的文件 if not filename.startswith('.') and filename.endswith('.pptx'): files.append(filename) return sorted(files)