Phi*_*hil 9 python console notepad++ utf-8
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()
Run Code Online (Sandbox Code Playgroud)
它遍历每个文件-> 我可以看到这一点。但是在它完成后,在我的情况下,字符集仍然是 ANSI:/
谁能帮我?
Har*_*vey 10
这是对我有用的:
转到Notepad++ -> 插件 -> 插件管理。
查找并安装Python Script插件。
使用Plugins -> Python Script -> New script创建新的 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()
Run Code Online (Sandbox Code Playgroud)
替换C:\\Users\\YourUsername\\Desktop\\txtFolder为文件所在的 Windows 文件夹的路径。
脚本处理.txt和.csv文件并忽略文件夹中的所有其他文件。
使用插件运行脚本-> Python 脚本 -> 脚本 -> 脚本名称
小智 6
您还可以在此处录制和回放宏。这对我有用,因为插件管理器不知何故损坏了,我没有可用的 Python。
您可以通过选择来回放宏
由于文件在处理后关闭,因此您将知道哪些文件尚未处理。
明白了我的错误。我的记事本是德文的。因此,请注意它是否称为“编码”或在我的情况下称为“Kodierung”和“在没有 BOM 的情况下转换为 UTF-8”是“Konvertiere zu UTF-8 ohne BOM”
那帮我解决了!