notepad++批量转换文件编码

来源:互联网 发布:http load windows 64 编辑:程序博客网 时间:2024/06/07 06:11

原出处:http://stackoverflow.com/questions/7256049/notepad-converting-ansi-encoded-file-to-utf-8

Here some simple steps to convert multiple files via Notepad++ without messing up with special characters (for ex. diacritical marks).

  1. Run Notepad++ and then open menu Plugins->Plugin Manager->Show Plugin Manager
  2. Install Python Script. When plugin is installed, restart the application.
  3. Choose menu Plugins->Python Script->New script.
  4. Choose its name, and then past the following code:

convertToUTF8.py

import os;import sys;filePathSrc="C:\\Users\\" # Path to the folder with files to convertfor root, dirs, files in os.walk(filePathSrc):    for fn in files:         if fn[-4:] == '.xml': # Specify type of the files            notepad.open(root + "\\" + fn)                  notepad.runMenuCommand("Encoding", "Convert to UTF-8")            notepad.save()            notepad.close()

After all, run the script


注意事项:操作前必须把notepad++语言设置成英文。否则执行没效果。参考:http://blog.csdn.net/a_flying_bird/article/details/51263375

即点击下面的菜单,不知道执行了没有,可以到代码里面加个打印 print "Convert to ANSI"   ,打开菜单里面的 Show Console 可以看到Python打印结果。


如果要转化为ANSI 就把插件代码改为下面,说明一下下面的fn[-2:],指寻找后面2个字符匹配的路径后缀为.h ,如果你要匹配.php ,则应该是fn[-4:]

import os;import sys;sys.stdout = consoleprint "Convert to ANSI" filePathSrc="E:\\CodeGames\\pf_win-master" # Path to the folder with files to convertfor root, dirs, files in os.walk(filePathSrc):    for fn in files:         if fn[-2:] == '.h': # Specify type of the files            notepad.open(root + "\\" + fn)                  notepad.runMenuCommand("Encoding", "Convert to ANSI")            notepad.save()            notepad.close()


原创粉丝点击