代码:
import os import re def remove_korean_text(srt_content): # 定义韩文字符的Unicode范围 pattern = re.compile(r'[\uac00-\ud7a3]+', re.UNICODE) # 使用正则表达式替换韩文字符为空 cleaned_content = re.sub(pattern, '', srt_content) return cleaned_content def process_srt_files(directory): # 遍历指定目录下的所有文件 for filename in os.listdir(directory): if filename.endswith(".srt"): file_path = os.path.join(directory, filename) try: with open(file_path, 'r', encoding='utf-8') as file: srt_content = file.read() # 移除韩文内容 cleaned_srt_content = remove_korean_text(srt_content) # 创建新的文件名 new_filename = filename.replace(".srt", "_cleaned.srt") new_file_path = os.path.join(directory, new_filename) # 将清理后的内容写入新的文件 with open(new_file_path, 'w', encoding='utf-8') as file: file.write(cleaned_srt_content) print(f"韩文内容已从 {filename} 中移除,并保存到新文件 {new_filename}") except Exception as e: print(f"处理文件 {filename} 时发生错误: {e}") # 替换以下路径为你的目标目录 directory_path = r'C:\xinzi' process_srt_files(directory_path)
分类:
python小程序
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
2021-09-25 win10设置护眼命令
2019-09-25 windows安装python64位和32位的方法
2019-09-25 win10驱动签名禁用与启动