Python将繁体文件批量重命名简体中文文件

 参考:https://blog.csdn.net/u012052268/article/details/77823970

繁体转简体.py文件统一目录下放入langconv.py和zh_wiki.py。

https://raw.githubusercontent.com/skydark/nstools/master/zhtools/langconv.py
https://raw.githubusercontent.com/skydark/nstools/master/zhtools/zh_wiki.py

os.walk时候貌似因为文件名已经被修改了,导入递归遍历不完全,多跑几次程序就好了。。。

#繁体转简体.py
from langconv import *
import os,stat
root_path='H:\新建文件夹'
# root_path=r'K:\新建文件夹\test'

def chmod(path):
    os.chmod(path, stat.S_IWRITE)
    os.chmod(path, stat.S_IRWXO)
    os.chmod(path, stat.S_IRWXU)
def convert(root_path):
    for root,dirs,files in os.walk(root_path):
        for dir in dirs:
            chmod(os.path.join(root,dir))
            new_dir = Converter('zh-hans').convert(dir)
            if new_dir!=dir:
                os.rename(os.path.join(root,dir),os.path.join(root,new_dir))
                print(os.path.join(root,dir))
        for file in files:
            chmod(os.path.join(root,file))
            new_file = Converter('zh-hans').convert(file)
            if new_file!=file:
                os.rename(os.path.join(root,file),os.path.join(root,new_file))
                print(os.path.join(root,file))

        # print(file)
if __name__ == '__main__':
    convert(root_path)





 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值