随笔 - 633,  文章 - 0,  评论 - 13,  阅读 - 48万
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

代码:

复制代码
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)
复制代码

 

posted on   大话人生  阅读(21)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 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驱动签名禁用与启动
点击右上角即可分享
微信分享提示