• Notepad++ 批量修改文件编码格式


    一、安装notepad++ 插件管理器(PluginManager)

    进入下面地址 https://github.com/bruderstein/nppPluginManager/releases 下载对应的版本

    解压至notepad++ 的plugins目录,重启即可

    ps: 7.6x以上版本,不能直接复制到notepad目录下。需要在plugins目录下,新建立PluginManager目录。然后把PluginManager.dll拷贝到此目录下,才能够显示出来效果

    二、安装Python Script 插件

    1. Run Notepad++ and then open menu Plugins->Plugin Manager->Show Plugin Manager

      运行notepad++ 打开插件--》插件管理器--》显示插件管理

      2、Install Python Script. When plugin is installed, restart the application.

      安装Python Script 等待安装完毕,重启应用

     三、新建python脚本,进行格式转换

    1. Choose menu Plugins->Python Script->New script.
    2. 选择插件--》python 脚本--》新建脚本

     

    1. Choose its name, and then past the following code:

      选择当前目录,新建名称为“convertToUTF8.py” 的脚本,脚本内容如下

    import os
    import sys
    sys.stdout = console
    
    filePathSrc="E:\new\" # Path to the folder with files to convert
    
    for root, dirs, files in os.walk(filePathSrc):
        for fn in files:
            print fn[-5:]
            if fn[-5:]=='.json':# Specify type of the files
                print fn[-5:]
                notepad.open(root + "\" + fn)
                notepad.runMenuCommand("Encoding","Convert to UTF-8")
                notepad.save()
                notepad.close()

     重启后则可以看到相应的脚本名称,并可以运行脚本

      如果要转化为ANSI 就把下面UTF-8改为ANSI既可,说明一下下面的fn[-5:],指寻找后面5个字符匹配的路径后缀为.html ,如果你要匹配.cpp ,则应该是fn[-4:],下面包含了.html .cpp一起修改。转换成不同的编码格式,只需修改 Convert to UTF-8 为下面菜单的红色框里面对应项即可。我的是notepad++7.5.8的,不同版本可能稍有不同。设置为跟自己版本一致即可。

    import os
    import sys
    sys.stdout = console
    
    filePathSrc="E:\new\" # Path to the folder with files to convert
    
    for root, dirs, files in os.walk(filePathSrc):
        for fn in files:
            print fn[-5:]
            if fn[-5:]== '.html' or fn[-4:]=='.cpp':# Specify type of the files
                print fn[-5:]
                notepad.open(root + "\" + fn)
                notepad.runMenuCommand("Encoding","Convert to UTF-8")
                notepad.save()
                notepad.close()

    运行结束后就会返现 编码格式批量转换成功

    四、在这里需要说明的以下注意几点

    1. notepad ++ 必须是在 英文状态下上述 方法才有效
    2. filePathSrc 路径中不能包含中文 
    3. python不支持tab 和空格混用 缩进,所以最好是打开notepad++ 的 View--》显示空格与制表符 如上面图所示

  • 相关阅读:
    CSS color
    Python 集成开发环境(IDE)
    Flexible and Economical UTF-8 Decoder
    方程式组织EQUATION DRUG平台解析(提纲) —方程式组织系列分析报告之四
    Windows Server 2008 IE 无法调整安全级别
    蟑螂数据库
    MySQL OCP
    TCP协议疑难杂症全景解析
    数据库资源博客---小麦苗BEST
    C++并发实战 与多线程
  • 原文地址:https://www.cnblogs.com/ningy1009/p/13683919.html
Copyright © 2020-2023  润新知