I have a simple script in Python, in which I am trying to traverse all files in a folder and change them to UTF-8 encoding using Notepad++.
import os;
import sys;
import Npp;
Npp.editor.write('Starting\r\n')
filePathSrc="C:\\SomePath"
Npp.editor.write('FilePath: ' + str(filePathSrc) + '\r\n')
try:
for root, dirs, files in os.walk(filePathSrc):
for fn in files:
if fn[-4:] == '.txt' or fn[-4:] == '.xml' or fn[-5:] == '.html':
notepad.open(root + "\\" + fn)
console.write(root + "\\" + fn + "\r\n")
notepad.runMenuCommand("Encoding", "Encode in UTF-8")
notepad.save()
notepad.close()
Npp.editor.write('Converted ' + str(fn))
except Exception as ex:
Npp.editor.write('Error occured\r\n')
Npp.editor.write(str(ex))
However, when I click on Plugins -> Python Script -> Scripts -> MySript, all I get is:
Starting
FilePath: C:\SomePath
Error occured
name 'notepad' is not defined
When searching the Internet, I have never found anyone with the same problem. All similar problems were caused because people were trying to run the script outside of Notepad++. However, I am getting the error when using Notepad++ plugin directly.
notepad?notepaddefined? Orconsolefor that matter. Not in the code that you've posted.