| import os | |
| from pathlib import Path | |
| # 要处理的根目录 | |
| root_dirs = ["train/video", "train/audio", "val/video", "test/video"] | |
| for path in root_dirs: | |
| p = Path(path) | |
| if not p.exists(): | |
| print(f"❌ 路径不存在: {p}") | |
| continue | |
| # 获取所有 .pth 文件的文件名(不含路径) | |
| filenames = sorted([f.name for f in p.glob("*.pth")]) | |
| # 输出文件路径:train/video → train/video.txt | |
| output_txt = p.parent / f"{p.name}.txt" | |
| with open(output_txt, "w") as f: | |
| for name in filenames: | |
| f.write(name + "\n") | |
| print(f"✅ 生成文件: {output_txt},共 {len(filenames)} 个条目") | |