Created
November 24, 2015 03:49
-
-
Save gavxin/4b6edc6af3f33ad085aa to your computer and use it in GitHub Desktop.
notepad++ python script plugin script for convert files to UTF8 encoding and Unix EOL.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#-*- encoding:gb2312 -*- | |
# | |
# Notepad++ Python script plugin script. | |
# For converting file encoding & lineending. | |
# | |
import os; | |
import sys; | |
filter_exts = [".h", ".cpp", ".c"] | |
SC_CP_UTF8 = 65001 | |
SC_EOL_LF = 2 | |
def convert(dir): | |
for root, dirs, files in os.walk(dir): | |
for f in files: | |
file_name, file_ext = os.path.splitext(f); | |
if file_ext in filter_exts: | |
path = root + "\\" + f | |
notepad.open(path) | |
console.write(path) | |
if editor.getEOLMode() != SC_EOL_LF: | |
answer = notepad.messageBox("文件" + path + " EOL将被转换成Unix格式(lf),是否确定?", "Confirm", MESSAGEBOXFLAGS.YESNOCANCEL) | |
if answer == MESSAGEBOXFLAGS.RESULTYES: | |
editor.convertEOLs(SC_EOL_LF) | |
notepad.save() | |
if answer == MESSAGEBOXFLAGS.RESULTCANCEL: | |
notepad.close() | |
return | |
if editor.getCodePage() != SC_CP_UTF8: | |
console.write(" code page:" + repr(editor.getCodePage())) | |
answer = notepad.messageBox("文件" + path + "将要被转换成utf8格式,是否确定?", "Confirm", MESSAGEBOXFLAGS.YESNOCANCEL) | |
if answer == MESSAGEBOXFLAGS.RESULTYES: | |
notepad.runMenuCommand("Encoding", "Convert to UTF-8") | |
notepad.save() | |
if answer == MESSAGEBOXFLAGS.RESULTCANCEL: | |
notepad.close() | |
return | |
notepad.close() | |
console.write("\r\n") | |
p = notepad.prompt("请输入目录路径", "输入目录路径") | |
if p: | |
convert(p) | |
Limour-dev
commented
Apr 1, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment