最近接手一些code,拿到手看了下编码格式,和自己习惯的UTF-8, Unix(LF)格式不一致,首先要做的就是修改编码格式,于是找到了基于notepad++的批处理方式,记录之。

环境

1
2
3
notepad++ v8.2.1 x64

win 11

安装python script插件

image-20220419124121908

新建脚本

Choose menu Plugins->Python Script->New script.

1
2
3
4
5
6
7
8
9
10
11
12
13
import os;
import sys;
filePathSrc="F:\\Workspace\\test\\" # Path to the folder with files to convert
for root, dirs, files in os.walk(filePathSrc):
for fn in files:
if fn[-2:] == '.c' or fn[-2:] == '.h': # Specify type of the files
notepad.open(root + "\\" + fn)
notepad.runMenuCommand("Encoding", "Convert to UTF-8") # convent to utf-8
notepad.runMenuCommand("EOL Conversion", "Unix (LF)") # convent to unix LF
notepad.save()
notepad.close()


运行脚本

image-20220419124428641

注意事项

1.notepad ++ 必须是在 英文状态下上述 方法才有效
2.filePathSrc 路径中不能包含中文

引用

https://www.csdn.net/tags/MtTaMgzsODA3NTY5LWJsb2cO0O0O.html