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--》顯示空格與制表符 如上面圖所示


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM