Notepad++ 转换为 UTF-8 多个文件
Notepad++ convert to UTF-8 multiple files
Notepad++的功能"Convert to UTF-8 without BOM"真不错。但是我有 200 个文件,所有文件都需要隐藏。因此我找到了这个 python 脚本:
import os;
import sys;
filePathSrc="C:\Temp\UTF8"
for root, dirs, files in os.walk(filePathSrc):
for fn in files:
if fn[-4:] != '.jar' and fn[-5:] != '.ear' and fn[-4:] != '.gif' and fn[-4:] != '.jpg' and fn[-5:] != '.jpeg' and fn[-4:] != '.xls' and fn[-4:] != '.GIF' and fn[-4:] != '.JPG' and fn[-5:] != '.JPEG' and fn[-4:] != '.XLS' and fn[-4:] != '.PNG' and fn[-4:] != '.png' and fn[-4:] != '.cab' and fn[-4:] != '.CAB' and fn[-4:] != '.ico':
notepad.open(root + "\" + fn)
console.write(root + "\" + fn + "\r\n")
notepad.runMenuCommand("Encoding", "Convert to UTF-8 without BOM")
notepad.save()
notepad.close()
它遍历每个文件 -> 我可以看到这个。但是完成后,字符集在我的例子中仍然是 ANSI :/
谁能帮帮我?
我理解错了。我的记事本是德文的。所以请注意它是否被称为 "Encoding" 或者在我的情况下 "Kodierung" 和 "Convert to UTF-8 without BOM" 是 "Konvertiere zu UTF-8 ohne BOM"
这对我很有帮助!
以下是对我有用的方法:
转到 Notepad++ -> 插件 -> 插件管理。
查找并安装 Python Script 插件。
使用 插件创建新的 python 脚本 -> Python 脚本 -> 新脚本.
将此代码插入您的脚本:
import os;
import sys;
filePathSrc="C:\Users\YourUsername\Desktop\txtFolder"
for root, dirs, files in os.walk(filePathSrc):
for fn in files:
if fn[-4:] == '.txt' or fn[-4:] == '.csv':
notepad.open(root + "\" + fn)
console.write(root + "\" + fn + "\r\n")
notepad.runMenuCommand("Encoding", "Convert to UTF-8")
notepad.save()
notepad.close()
将 C:\Users\YourUsername\Desktop\txtFolder
替换为文件所在的 Windows 文件夹的路径。
脚本适用于 .txt
和 .csv
文件并忽略文件夹中的所有其他文件。
运行 带有 插件的脚本 -> Python 脚本 -> 脚本 -> 脚本名称
您还可以在这里录制和回放宏。这对我有用,因为插件管理器不知何故坏了我没有 Python 可用。
- 将一组文件(或全部 - 我认为文件的最大数量有限制)拖到记事本++中
- 宏 -> 开始录制
- 进行转换
- 保存文件
- 关闭文件
- 宏 -> 停止录制
您可以通过选择
来回放宏
- 宏 -> 运行 一个宏多次
- 输入一个值,以便处理所有文件
由于文件在处理后关闭,您将知道哪些文件尚未处理。
Notepad++的功能"Convert to UTF-8 without BOM"真不错。但是我有 200 个文件,所有文件都需要隐藏。因此我找到了这个 python 脚本:
import os;
import sys;
filePathSrc="C:\Temp\UTF8"
for root, dirs, files in os.walk(filePathSrc):
for fn in files:
if fn[-4:] != '.jar' and fn[-5:] != '.ear' and fn[-4:] != '.gif' and fn[-4:] != '.jpg' and fn[-5:] != '.jpeg' and fn[-4:] != '.xls' and fn[-4:] != '.GIF' and fn[-4:] != '.JPG' and fn[-5:] != '.JPEG' and fn[-4:] != '.XLS' and fn[-4:] != '.PNG' and fn[-4:] != '.png' and fn[-4:] != '.cab' and fn[-4:] != '.CAB' and fn[-4:] != '.ico':
notepad.open(root + "\" + fn)
console.write(root + "\" + fn + "\r\n")
notepad.runMenuCommand("Encoding", "Convert to UTF-8 without BOM")
notepad.save()
notepad.close()
它遍历每个文件 -> 我可以看到这个。但是完成后,字符集在我的例子中仍然是 ANSI :/
谁能帮帮我?
我理解错了。我的记事本是德文的。所以请注意它是否被称为 "Encoding" 或者在我的情况下 "Kodierung" 和 "Convert to UTF-8 without BOM" 是 "Konvertiere zu UTF-8 ohne BOM"
这对我很有帮助!
以下是对我有用的方法:
转到 Notepad++ -> 插件 -> 插件管理。
查找并安装 Python Script 插件。
使用 插件创建新的 python 脚本 -> Python 脚本 -> 新脚本.
将此代码插入您的脚本:
import os;
import sys;
filePathSrc="C:\Users\YourUsername\Desktop\txtFolder"
for root, dirs, files in os.walk(filePathSrc):
for fn in files:
if fn[-4:] == '.txt' or fn[-4:] == '.csv':
notepad.open(root + "\" + fn)
console.write(root + "\" + fn + "\r\n")
notepad.runMenuCommand("Encoding", "Convert to UTF-8")
notepad.save()
notepad.close()
将 C:\Users\YourUsername\Desktop\txtFolder
替换为文件所在的 Windows 文件夹的路径。
脚本适用于 .txt
和 .csv
文件并忽略文件夹中的所有其他文件。
运行 带有 插件的脚本 -> Python 脚本 -> 脚本 -> 脚本名称
您还可以在这里录制和回放宏。这对我有用,因为插件管理器不知何故坏了我没有 Python 可用。
- 将一组文件(或全部 - 我认为文件的最大数量有限制)拖到记事本++中
- 宏 -> 开始录制
- 进行转换
- 保存文件
- 关闭文件
- 宏 -> 停止录制
您可以通过选择
来回放宏- 宏 -> 运行 一个宏多次
- 输入一个值,以便处理所有文件
由于文件在处理后关闭,您将知道哪些文件尚未处理。