网站首页 > 精选文章 正文
一个文件夹里面有很多个srt字幕文件,如何借助kimichat来自动批量合并呢?
在kimichat对话框中输入提示词:
你是一个Python编程专家,完成如下的编程任务:
这个文件夹:D:\downloads\life.on.our.planet.(2023).tv.s01.chi.12cd\新建文件夹
里面有很多srt后缀的文件,将所有srt文件按照名称顺序,合并成一个文件
kimichat给出的Python脚本源代码:
import os
# 设置文件夹路径
folder_path = 'D:\\downloads\\life.on.our.planet.(2023).tv.s01.chi.12cd\\新建文件夹'
# 确保文件夹存在
if not os.path.exists(folder_path):
print("指定的文件夹不存在,请检查路径是否正确。")
else:
# 获取文件夹中所有的srt文件,按文件名排序
srt_files = sorted([f for f in os.listdir(folder_path) if f.endswith('.srt')])
# 合并文件的输出路径
output_file = os.path.join(folder_path, 'merged.srt')
# 打开输出文件准备写入
with open(output_file, 'w', encoding='utf-8') as outfile:
# 遍历所有的srt文件并合并
for srt_file in srt_files:
file_path = os.path.join(folder_path, srt_file)
with open(file_path, 'r', encoding='utf-8') as infile:
for line in infile:
outfile.write(line)
print(f"所有srt文件已合并到 {output_file}")
在vscode中运行这个Python程序,成功了:
猜你喜欢
- 2025-09-13 使用VSCode来书写你的Jupyter Notebooks
- 2025-09-13 在VSCode中使用uv管理Python项目_用vscode写python怎么运行
- 2025-09-13 Mac M2芯片 VSCode配置C#开发环境
- 2025-09-13 配置vscode远程访问docker_vscode远程window开发
- 2025-09-13 普通人 如何 利用 类似 ChatGPT AI 编写程序
- 2025-09-13 在Vs code中使用sftp插件以及连接windows远程sftp协议部署指导
- 最近发表
-
- 使用VSCode来书写你的Jupyter Notebooks
- 在VSCode中使用uv管理Python项目_用vscode写python怎么运行
- Mac M2芯片 VSCode配置C#开发环境
- 配置vscode远程访问docker_vscode远程window开发
- 普通人 如何 利用 类似 ChatGPT AI 编写程序
- 在Vs code中使用sftp插件以及连接windows远程sftp协议部署指导
- 零代码编程:用kimichat合并一个文件夹下的多个文件
- Windows 10下使用编译并使用openCV
- 基于Springboot + vue3实现的汽车美容与保养网
- 超级右键iRightMouse--Mac强大工具
- 标签列表
-
- 向日葵无法连接服务器 (32)
- git.exe (33)
- vscode更新 (34)
- dev c (33)
- git ignore命令 (32)
- gitlab提交代码步骤 (37)
- java update (36)
- vue debug (34)
- vue blur (32)
- vscode导入vue项目 (33)
- vue chart (32)
- vue cms (32)
- 大雅数据库 (34)
- 技术迭代 (37)
- 同一局域网 (33)
- github拒绝连接 (33)
- vscode php插件 (32)
- vue注释快捷键 (32)
- linux ssr (33)
- 微端服务器 (35)
- 导航猫 (32)
- 获取当前时间年月日 (33)
- stp软件 (33)
- http下载文件 (33)
- linux bt下载 (33)