notepad++ 批量转所有文件编码格式为UTF-8

1、安装notepad++及PythonScript_3.0.18.0插件

建议两者都保持默认路径安装x64版本:

阿里云盘分享https://www.alipan.com/s/xVUDpY8v5QL安装好后如下图:

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、确认已经处理的数量和文件夹数量是否一致

相关推荐
舟遥遥娓飘飘13 小时前
面向零基础初学者,从环境搭建到发布上线,手把手教你开发第一个微信小程序(第3章-认识项目结构)
微信小程序·小程序·notepad++
优睿远行14 小时前
微信小程序自定义组件开发实战:从封装到发布的全流程指南
微信小程序·小程序·notepad++
喜欢南方姑娘3 天前
微信小程序热更新-用户打开小程序时检测版本自动更新
微信小程序·小程序·notepad++
yzx9910133 天前
从零开始写一个微信小程序:完整代码实战指南(入门篇)
微信小程序·小程序·notepad++
fengyehongWorld4 天前
Notepad++ NppExec插件的使用
notepad++
fengyehongWorld7 天前
Notepad++ 常用插件
notepad++
fengyehongWorld7 天前
Notepad++ PythonScript插件,添加自定义文本转换功能
notepad++
x***r1518 天前
Notepad++ 6.6.9安装步骤详解(附Notepad++离线安装教程)
notepad++
Uso_Magic12 天前
Notepad++ 批量光标编辑方法。
notepad++
秋916 天前
Notepad++ 完全使用手册:从入门到精通
notepad++