繁体   English   中英

Notepad ++ Python脚本无法打开文件名中包含特殊字符的文件

[英]Notepad++ Python script can't open file with special characters in filename

我需要通过记事本++将某些文件的编码更改为UTF-8。 我为Python脚本插件找到了该脚本,该脚本可更改文件夹中所有文件的编码:

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:] == '.txt': # Specify type of the files
            notepad.open(root + "\\" + fn)      
            notepad.runMenuCommand("Encoding", "Convert to UTF-8")
            notepad.save()
            notepad.close()

它对我很有用,除非foler中的文件在文件名中具有异常的非英语字符(例如é,Ø,ß等)。 关于此文件,Notepad ++显示了创建新文件“ C:\\ Somefile.txt不存在。创建它吗?”的建议。 而不是打开它。

请帮助教Notepad ++,此脚本也会打开此文件。

我认为这个问题是由于单词之间的间隔而出现的。 Notepad ++有这样的问题。 如果可行,这里有一个解决方案http://sourceforge.net/p/notepad-plus/discussion/331753/thread/bdf6db82

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM