本文共 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/