1、安装notepad++及PythonScript_3.0.18.0插件
建议两者都保持默认路径安装x64版本:
2、new Script,新建脚本,文件名为ConvertEncoding
3、自动打开脚本,复制粘贴以下内容,并将文件夹路径修改为需要转换的文件夹路径
默认路径:C:\Users\用户\AppData\Roaming\Notepad++\plugins\config\PythonScript\scripts
python
import os
import sys
#编码格式
#FORMAT_CONV2_AS_UTF_8 = UTF-8
#FORMAT_CONV2_UTF_8 = UTF-8-BOM
#结尾格式
#MENUCOMMAND.FORMAT_TODOS = Windows
#MENUCOMMAND.FORMAT_TOMAC = MAC
#MENUCOMMAND.FORMAT_TOUNIX = Unix
# Path to the folder with files to convert
dir_to_convert = "C:\\Users\\ycy\\Desktop\\test"
total_files = 0
for root, dirs, files in os.walk(dir_to_convert):
for file in files:
#if file[-4:] == '.cpp' or file[-2:] == '.h': # Specify type of the files
notepad.open(root + "\\" + file)
notepad.menuCommand(MENUCOMMAND.FORMAT_CONV2_AS_UTF_8)
notepad.menuCommand(MENUCOMMAND.FORMAT_TOUNIX)
notepad.save()
notepad.close()
print(f"{file} 成功")
total_files += 1
print(f"\n总计文件数量: {total_files}")
4、先show console显示命令行,然后Run
5、确认已经处理的数量和文件夹数量是否一致