I write a python script which help me to convert all files in UTF-8 without BOM in specific extension. However, the error is stopped on the statement of notepad.open(fileName), the error seem I am missing of argument of unicode, but I search in python script, the notepad.open should pass the filename only. I currently usePhython Script version 1.0.8, do you know why?
Thanks all.
The error in Console
File "C:\Users\Chris\AppData\Roaming\Notepad++\plugins\Config\PythonScript\scripts\Convert file to UTF-8 without BOM.py", line 12, in <module>
notepad.open(fileName)
Boost.Python.ArgumentError: Python argument types in
Notepad.open(Notepad, unicode)
did not match C++ signature:
open(class NppPythonScript::NotepadPlusWrapper {lvalue}, char const * filename)
Source code
# -*- coding: UTF-8 -*-importos;importsys;filePathSrc=u'D:\\TEMP\\a'console.write('Source: '+filePathSrc+'\n')forroot,dirs,filesinos.walk(filePathSrc):forfninfiles:iffn[-4:]=='.srt'orfn[-4:]=='.ssa'orfn[-4:]=='.ass':fileName=root+"\\"+fnconsole.write("fileName: "+fileName+'\n')notepad.open(fileName)notepad.runMenuCommand("Encoding","Convert to UTF-8 without BOM")notepad.save()notepad.close()
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Dear all,
I write a python script which help me to convert all files in UTF-8 without BOM in specific extension. However, the error is stopped on the statement of notepad.open(fileName), the error seem I am missing of argument of unicode, but I search in python script, the notepad.open should pass the filename only. I currently usePhython Script version 1.0.8, do you know why?
Thanks all.
The error in Console
Source code
By using
filePathSrc = u'D:\TEMP\a'
you turn everything returned by os.walk into a unicode string but
open function expects normal byte string.
Use filePathSrc = 'D:\TEMP\a' instead.
Cheers
Claudia