博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Python将繁体文件批量重命名简体中文文件
阅读量:4300 次
发布时间:2019-05-27

本文共 983 字,大约阅读时间需要 3 分钟。

 参考:

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

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

#繁体转简体.pyfrom langconv import *import os,statroot_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)

 

转载地址:http://bkxws.baihongyu.com/

你可能感兴趣的文章
Python区间库python-intervals
查看>>
django admin 登录用户名密码错误提示
查看>>
python3 AttributeError: 'function' object has no attribute 'func_name'
查看>>
解决ubuntu下修改my.cnf设置字符集导致mysql无法启动
查看>>
根据进程的PID查询对应端口号
查看>>
Ubuntu安装指定版本的docker
查看>>
MySQL show processlist过滤
查看>>
Python日志logging的levelname格式化参数1.1s小记
查看>>
ubuntu虚拟机VMware桥接模式无法自动化获取IP的解决方法
查看>>
Python debug 报错:SystemError: unknown opcode
查看>>
Python将树结构转换成字典形式的多级菜单结构,写入json文件
查看>>
关闭linux防火墙让windows宿主机访问ubuntu虚拟机web服务以及docker
查看>>
pycharm 找不到同目录文件,但是终端中正常的小记
查看>>
安装了grpc但是无法导入:ImportError: No module named 'grpc'
查看>>
Python中logging模块的基本用法
查看>>
Python查看第三方库、包的所有可用版本,历史版本
查看>>
一键将Python2代码转成Python3小记,
查看>>
Python要求O(n)复杂度求无序列表中第K的大元素
查看>>
Python 各种进制互相转换的函数
查看>>
python的单例理解、__new__、新式类object以及python2和python3下__new__的区别。
查看>>