notepad++批量转换文件编码

7 篇文章 0 订阅

更新2019-8-25 12:52:29

一、插件管理器安装

notepad++找不到PluginManager插件管理器,到下面链接下载32位版本PluginManager_v1.4.12_UNI.zip解压后放到plugins目录下重启既可。64位版本下载PluginManager_v1.4.12_x64.zip对应的版本。7.6x以上版本。不能直接复制到notepad目录下。需要在plugins目录下。新建立PluginManager目录。然后把PluginManager.dll拷贝到此目录下,才能够显示出来效果。其他不可用插件也按此方法基本能解决。

下载:https://github.com/bruderstein/nppPluginManager/releases

二、单独安装

单独安装python script:我使用的notepad++是7.8.6版本。到github网站下载python script好像现在32/64都支持了,32位下载PythonScript_Full_3.0.1.0.zip,64位下载PythonScript_Full_3.0.1.0_x64.zip。下载后拷贝到Notepad++下的plugins目录下解压。

解压后修改目录名称为PythonScript。具体如下图。重新打开notepad++即可使用。

下载:https://github.com/bruderstein/PythonScript

 

原出处: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 convert
for 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打印结果。

操作步骤:

1、打开Python Script----NewScript

2、输入需要创建的脚本名称convertToUTF8,使用默认路径保存。如果是直接从以前的复制粘贴过来的,则需要重启一下notepad++。

3、在脚本文件中编辑python代码。重启notepad++。

4、重启后则可以看到相关的脚本名称了,保存上述代码后,进入插件中点击运行当前脚本。

Python没有花括号{},使用缩进来作为程序层次区分的标志,此外Python没有分号;以换行来实现程序语句的结束。如果要转化为ANSI 就把下面UTF-8改为ANSI既可,说明一下下面的fn[-2:],指寻找后面2个字符匹配的路径后缀为.h ,如果你要匹配.cpp ,则应该是fn[-4:],下面包含了.h .cpp一起修改。转换成不同的编码格式,只需修改 Convert to UTF-8 为下面菜单的红色框里面对应项即可。我的是notepad++7.5.6的,不同版本可能稍有不同。设置为跟自己版本一致即可。

 

import os;
import sys;
sys.stdout = console

filePathSrc="E:\\0_WorkSvn\\1_HxRadar\\3dparty" # Path to the folder with files to convert

for root, dirs, files in os.walk(filePathSrc):
    for fn in files: 
        if fn[-2:] == '.h' or fn[-4:] == '.cpp': # Specify type of the files
            notepad.open(root + "\\" + fn)      
            notepad.runMenuCommand("Encoding", "Convert to UTF-8")
            notepad.save()
            notepad.close()

 

 

 

 

 

 

  • 7
    点赞
  • 31
    收藏
    觉得还不错? 一键收藏
  • 7
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值