python批量转换utf8_批量编码转换utf-8

批量转换编码是很痛苦的事情,一种办法是自己去写代码来实现,你得解析判断文件编码的类型utf-8 utf-16 ansi ucs-2,然后判断,难保证都成功的转换。提供一种利用第三方工具批量转换成utf-8 ansi等。

安装nodepad++及插件

Plugins->Plugin Manager->Show Plugin Manager

Python Script安装重启Notepad++

Plugins->Python Script->New script

输入名字toUtf-8,然后复制下面python脚本

运行脚本Plugins->Python Script->scripts->toUtf-8

python脚本

转换utf-8、注意备份,是直接把文件编码转换,不支持中文路径

import os;

import sys;

from Npp import notepad #这里必须导入nodepad++ if i note this line, it says, "notepad is not defined"

filePathSrc="E:\\Beyond2\\"#"E:\\Songs2\\" # Path to the folder with files to convert

for root, dirs, files in os.walk(filePathSrc):

for fn in files:

if fn[-4:] == '.dtx': # Specify type of the files 判断指定的后缀名

notepad.open(root + "\\" + fn)

notepad.runMenuCommand("Encoding", "Convert to UTF-8")#想转成ANSI 替换UTF-8

notepad.save()

notepad.close()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值