注:操作有风险,请自行备份好数据,本教程仅供参考。
一. 安装/介绍
1. 官网-notepad++
2. github-pythonscript插件
打开notepad++, 在菜单栏选择: 插件->插件管理->可用, 搜索pythonScript并安装,

目录 | 介绍 |
---|---|
PythonScript\doc | 插件说明书 |
PythonScript\scripts | python文件目录(脚本需放置在此目录才可运行) |
二. 编写脚本并运行
- 添加脚本, 在菜单栏选择: 插件->Python Script->new Script, 新脚本命名为convertToUTF8.py
- 脚本内容如下:
# -*- coding: UTF-8 -*-
import os;
import sys;
sys.stdout = console
filePathSrc = "C:\\Convert" # 转换目录
num=0
# 遍历文件夹 for (root, dirs, files) in walk(roots)
#roots 代表需要遍历的根文件夹
#root 表示正在遍历的文件夹的名字(根/子)
#dirs 记录正在遍历的文件夹下的子文件夹集合
#files 记录正在遍历的文件夹中的文件集合
for root, dirs, files in os.walk(filePathSrc):
for fn in files:
if fn[-4:] == '.txt' : # 文件后缀
str = root + "\\" + fn
file = str.decode('GBK').encode('utf-8');
print "转换:"+file
num=num+1
notepad.open(file)
notepad.runMenuCommand("Encoding", "Convert to UTF-8")
notepad.save()
notepad.close()
print ("Convert to UTF-8 Finish : ", num)
- 根据所需转码的文件, 修改代码中的[转换目录]和[文件后缀],
- 设置notepad++显示语言为英文, 否则脚本运行无效果

- 打开控制台并运行脚本:
