<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Python script plugin console to open multiple files]]></title><description><![CDATA[<p dir="auto">I have a ‘filenames.txt’ where each line has the full path to a file, and I want to open all the files in the ‘filenames.txt’ from Python Script Plugin console. And here’s what I’m doing:</p>
<pre><code>f = open("C:/Users/junew/Desktop/filesnames.txt", "r");
lines = f.readlines(); 
for i in lines: 
  notepad.open(i)
</code></pre>
<p dir="auto">When I try lines[0], the output is</p>
<pre><code>'F:/06__Other_Models/Transport/round1/convert2/58542_\xd0\x9f\xd0\xbe\xd0\xb3\xd1\x80\xd1\x83\xd0\xb7\xd1\x87\xd0\xb8\xd0\xba.mtl\n'
</code></pre>
<p dir="auto">the true path is</p>
<pre><code>F:/06__Other_Models/Transport/round1/convert2/58542_Погрузчик.mtl
</code></pre>
<p dir="auto">I can open it using notepad.open(‘F:/06__Other_Models/Transport/round1/convert2/58542_Погрузчик.mtl’).  But from python console using above code, notepad++ keeps saying ‘File F:/06__Other_Models/Transport/round1/convert2/58542_Погрузчик.mtl doesn’t exist’, I think it has something to do with the non UTF-8 encoded file(names).</p>
<p dir="auto">Any idea how to get around it?</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/20934/python-script-plugin-console-to-open-multiple-files</link><generator>RSS for Node</generator><lastBuildDate>Wed, 18 Nov 2026 05:36:56 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/20934.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 24 Mar 2021 12:57:59 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Python script plugin console to open multiple files on Thu, 25 Mar 2021 17:50:57 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/june-wang" aria-label="Profile: June-Wang">@<bdi>June-Wang</bdi></a> said in <a href="/post/64348">Python script plugin console to open multiple files</a>:</p>
<blockquote>
<p dir="auto">The software I used to output my current data is unable to output unicode data</p>
</blockquote>
<p dir="auto">Unicode was invented in 1991 <a href="https://www.google.com/search?q=when+was+unicode+invented" rel="nofollow ugc">↗</a>, and UTF-8 encoding was invented in 1992 <a href="https://www.google.com/search?q=when+was+utf-8+invented" rel="nofollow ugc">↗</a>.  Software developers have had 30 years to adapt.  And most software I’ve seen from the last decade or so knows how to use UTF-8.  Any software still under active development should have figured out UTF-8 by now; if they haven’t, and if you (or a company you work for) are a paying customer, I would start making frequent requests to find out what their schedule for upgrading from pre-1990’s technology is.</p>
<p dir="auto">That said, I’m glad that Notepad++ (plus plugins) is able to help you overcome this extreme deficiency in  output ability of this other software.  Good luck.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/64350</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64350</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Thu, 25 Mar 2021 17:50:57 GMT</pubDate></item><item><title><![CDATA[Reply to Python script plugin console to open multiple files on Thu, 25 Mar 2021 17:35:05 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ekopalypse" aria-label="Profile: Ekopalypse">@<bdi>Ekopalypse</bdi></a><br />
Nice, that worked!<br />
The software I used to output my current data is unable to output unicode data when it comes to foreign language, sometimes it’s ANSI in Npp++, sometimes it’s Character sets selected, but, i.e. Хромм_слабe turns out to be 孚把抉技技_扼抖忘忌e . Now I need to import those data to another software, but it only accepts UTF-8 encoded. So I have to convert ANSI to UTF-8, and manually fix the ones that have Character sets selected, otherwise they show up as boxes. Not fun :(</p>
]]></description><link>https://community.notepad-plus-plus.org/post/64348</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64348</guid><dc:creator><![CDATA[June Wang]]></dc:creator><pubDate>Thu, 25 Mar 2021 17:35:05 GMT</pubDate></item><item><title><![CDATA[Reply to Python script plugin console to open multiple files on Thu, 25 Mar 2021 14:37:10 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/june-wang" aria-label="Profile: June-Wang">@<bdi>June-Wang</bdi></a></p>
<p dir="auto">If you use the code I posted, you can distinguish between<br />
ANSI and CharacterSet by checking for ANSI, with another elif branch</p>
<pre><code class="language-py">elif encoding == 'ANSI'
...
</code></pre>
<p dir="auto">But why would you want to do that??</p>
]]></description><link>https://community.notepad-plus-plus.org/post/64332</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64332</guid><dc:creator><![CDATA[Ekopalypse]]></dc:creator><pubDate>Thu, 25 Mar 2021 14:37:10 GMT</pubDate></item><item><title><![CDATA[Reply to Python script plugin console to open multiple files on Thu, 25 Mar 2021 14:32:41 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ekopalypse" aria-label="Profile: Ekopalypse">@<bdi>Ekopalypse</bdi></a> said in <a href="/post/64322">Python script plugin console to open multiple files</a>:</p>
<blockquote>
<p dir="auto">As for ANSI and CharacterSet, they are basically the same thing, they are the 8bit encoding.</p>
</blockquote>
<blockquote>
<pre><code>else: # ANSI and Character set
    notepad.runMenuCommand("Encoding", "Convert to UTF-8")
    notepad.save()
    notepad.close()
</code></pre>
</blockquote>
<p dir="auto">Thank you. So there’s no way to tell if a file is Character sets selected or not? But notepad.getEncoding() outputs differently tho.<br />
On Character sets selected file, it outputs</p>
<pre><code>Npp.BUFFERENCODING.COOKIE
</code></pre>
<p dir="auto">On ANSI selected file, it outputs</p>
<pre><code>Npp.BUFFERENCODING.ENC8BIT
</code></pre>
]]></description><link>https://community.notepad-plus-plus.org/post/64331</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64331</guid><dc:creator><![CDATA[June Wang]]></dc:creator><pubDate>Thu, 25 Mar 2021 14:32:41 GMT</pubDate></item><item><title><![CDATA[Reply to Python script plugin console to open multiple files on Thu, 25 Mar 2021 11:42:38 GMT]]></title><description><![CDATA[<p dir="auto">this<br />
UPDATE: A word of warning, Npp can only ACCEPT the coding, it has no chance to be 100 sure this is the correct one.<br />
should be<br />
UPDATE: A word of warning, Npp can only <code>ASSUME </code> the encoding, it has no chance to be 100 sure this is the correct one.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/64323</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64323</guid><dc:creator><![CDATA[Ekopalypse]]></dc:creator><pubDate>Thu, 25 Mar 2021 11:42:38 GMT</pubDate></item><item><title><![CDATA[Reply to Python script plugin console to open multiple files on Thu, 25 Mar 2021 11:36:35 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/june-wang" aria-label="Profile: June-Wang">@<bdi>June-Wang</bdi></a></p>
<p dir="auto">I guess this one should do what you are looking for.<br />
As for ANSI and CharacterSet, they are basically the same thing, they are the 8bit encoding.<br />
ANSI is what the system is currently configured with and CharacterSet can be used if you want to display a different 8bit encoding.<br />
For example, if you have a German setup, ANSI is equal to Windows-1252,<br />
but if you get a Russian text, you may need to select Windows-1251 to see the Cyrillic symbols.</p>
<pre><code class="language-py">import ctypes

from ctypes.wintypes import HWND, UINT, LPARAM, WPARAM, LPCWSTR

user32 = ctypes.WinDLL('user32')

LRESULT = LPARAM
SendMessage = user32.SendMessageW
SendMessage.argtypes = [HWND, UINT, WPARAM, LPARAM]
SendMessage.restype  = LRESULT

FindWindow = user32.FindWindowW
FindWindow.argtypes = [LPCWSTR, LPCWSTR]
FindWindow.restype  = HWND

FindWindowEx = user32.FindWindowExW
FindWindowEx.restype = HWND
FindWindowEx.argtypes = [HWND, HWND, LPCWSTR, LPCWSTR]

WM_USER             = 1024
SB_GETTEXTW         = WM_USER+13
SB_GETTEXTLENGTHW   = WM_USER+12


def get_assumed_encoding(statusbar_hwnd):
    buffer_length = user32.SendMessageW(statusbar_hwnd, SB_GETTEXTLENGTHW, 4, 0)
    buffer = ctypes.create_unicode_buffer(buffer_length+1)
    user32.SendMessageW(statusbar_hwnd, SB_GETTEXTW, 4, ctypes.addressof(buffer))
    return buffer.value

def main():
    npp_hwnd = FindWindow(u'Notepad++', None)
    statusbar_hwnd = FindWindowEx(npp_hwnd, None, u"msctls_statusbar32", None)

    # for each file in ... do
    encoding = get_assumed_encoding(statusbar_hwnd)
    if encoding == 'UTF-8':
        notepad.close()
    elif encoding in ['UTF-8-BOM', 'UCS-2 BE BOM', 'UCS-2 LE BOM']:
        # what to do here??
        pass
    else: # ANSI and Character set
        notepad.runMenuCommand("Encoding", "Convert to UTF-8")
        notepad.save()
        notepad.close()
        
main()
</code></pre>
<p dir="auto">UPDATE: A word of warning, Npp can only ACCEPT the coding, it has no chance to be 100 sure this is the correct one.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/64322</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64322</guid><dc:creator><![CDATA[Ekopalypse]]></dc:creator><pubDate>Thu, 25 Mar 2021 11:36:35 GMT</pubDate></item><item><title><![CDATA[Reply to Python script plugin console to open multiple files on Thu, 25 Mar 2021 06:05:05 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ekopalypse" aria-label="Profile: Ekopalypse">@<bdi>Ekopalypse</bdi></a> said in <a href="/post/64316">Python script plugin console to open multiple files</a>:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/june-wang" aria-label="Profile: June-Wang">@<bdi>June-Wang</bdi></a><br />
Do you want to find out which encoding has been assigned by notepad++?</p>
</blockquote>
<p dir="auto">Kind of, I don’t know much about encoding methods. Just trying to check if Encoding-&gt;Character sets selected in a file, continue; if NTF-8 selected, close; else, convert to NTF-8, save N close. I just read the other thread mentioned above, and put together this code.</p>
<pre><code>if notepad.runMenuCommand("Encoding", "Character sets") and notepad.getEncoding() =='Npp.BUFFERENCODING.COOKIE':
      continue
elseif notepad.runMenuCommand("Encoding", "NTF-8"):
   notepad.close()
else:
   notepad.runMenuCommand("Encoding", "Convert to UTF-8")
   notepad.save()
   notepad.close()
</code></pre>
<p dir="auto">Thought it should work. However, for a file that has Character sets selected, when I do notepad.getEncoding() from console, it returns Npp.BUFFERENCODING.COOKIE. But when I do a compare  notepad.getEncoding() ==‘Npp.BUFFERENCODING.COOKIE’, it returns false.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/64319</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64319</guid><dc:creator><![CDATA[June Wang]]></dc:creator><pubDate>Thu, 25 Mar 2021 06:05:05 GMT</pubDate></item><item><title><![CDATA[Reply to Python script plugin console to open multiple files on Wed, 24 Mar 2021 20:50:20 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/alan-kilborn" aria-label="Profile: Alan-Kilborn">@<bdi>Alan-Kilborn</bdi></a></p>
<p dir="auto">Eventually, we could find a solution to read the value from the status bar if that is really what is being looked for, but it must be clear that this is just an estimate from Npp and in the worst case it is just wrong.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/64318</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64318</guid><dc:creator><![CDATA[Ekopalypse]]></dc:creator><pubDate>Wed, 24 Mar 2021 20:50:20 GMT</pubDate></item><item><title><![CDATA[Reply to Python script plugin console to open multiple files on Wed, 24 Mar 2021 20:45:49 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ekopalypse" aria-label="Profile: Ekopalypse">@<bdi>Ekopalypse</bdi></a> said in <a href="/post/64316">Python script plugin console to open multiple files</a>:</p>
<blockquote>
<p dir="auto">Do you want to find out which encoding has been assigned by notepad++?</p>
</blockquote>
<p dir="auto">Is this one going to end <a href="https://community.notepad-plus-plus.org/post/58504">HERE</a>?</p>
]]></description><link>https://community.notepad-plus-plus.org/post/64317</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64317</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Wed, 24 Mar 2021 20:45:49 GMT</pubDate></item><item><title><![CDATA[Reply to Python script plugin console to open multiple files on Wed, 24 Mar 2021 20:29:54 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/june-wang" aria-label="Profile: June-Wang">@<bdi>June-Wang</bdi></a></p>
<p dir="auto">These commands are used to call menu items and just return true if a menu item was found.<br />
Do you want to find out which encoding has been assigned by notepad++?</p>
]]></description><link>https://community.notepad-plus-plus.org/post/64316</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64316</guid><dc:creator><![CDATA[Ekopalypse]]></dc:creator><pubDate>Wed, 24 Mar 2021 20:29:54 GMT</pubDate></item><item><title><![CDATA[Reply to Python script plugin console to open multiple files on Wed, 24 Mar 2021 20:14:59 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/peterjones" aria-label="Profile: PeterJones">@<bdi>PeterJones</bdi></a> <a class="plugin-mentions-user plugin-mentions-a" href="/user/ekopalypse" aria-label="Profile: Ekopalypse">@<bdi>Ekopalypse</bdi></a> <a class="plugin-mentions-user plugin-mentions-a" href="/user/alan-kilborn" aria-label="Profile: Alan-Kilborn">@<bdi>Alan-Kilborn</bdi></a><br />
Btw, anyone knows how to tell if a file selects ANSI or Character sets ? Right now if a file that has Character sets selected, and a file that has ANSI selected will both return true on the following commands.</p>
<pre><code>notepad.runMenuCommand("Encoding", 'Character sets')
notepad.runMenuCommand("Encoding", 'ANSI')
</code></pre>
]]></description><link>https://community.notepad-plus-plus.org/post/64315</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64315</guid><dc:creator><![CDATA[June Wang]]></dc:creator><pubDate>Wed, 24 Mar 2021 20:14:59 GMT</pubDate></item><item><title><![CDATA[Reply to Python script plugin console to open multiple files on Wed, 24 Mar 2021 14:07:34 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/alan-kilborn" aria-label="Profile: Alan-Kilborn">@<bdi>Alan-Kilborn</bdi></a> said in <a href="/post/64303">Python script plugin console to open multiple files</a>:</p>
<blockquote>
<p dir="auto">notepad.open(i.rstrip())</p>
</blockquote>
<p dir="auto">That worked ! Thank you all so much! <a class="plugin-mentions-user plugin-mentions-a" href="/user/ekopalypse" aria-label="Profile: Ekopalypse">@<bdi>Ekopalypse</bdi></a> <a class="plugin-mentions-user plugin-mentions-a" href="/user/peterjones" aria-label="Profile: PeterJones">@<bdi>PeterJones</bdi></a></p>
]]></description><link>https://community.notepad-plus-plus.org/post/64304</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64304</guid><dc:creator><![CDATA[June Wang]]></dc:creator><pubDate>Wed, 24 Mar 2021 14:07:34 GMT</pubDate></item><item><title><![CDATA[Reply to Python script plugin console to open multiple files on Wed, 24 Mar 2021 13:39:47 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/june-wang" aria-label="Profile: June-Wang">@<bdi>June-Wang</bdi></a> said in <a href="/post/64294">Python script plugin console to open multiple files</a>:</p>
<blockquote>
<p dir="auto">notepad.open(i)</p>
</blockquote>
<p dir="auto">So maybe OP should try:</p>
<p dir="auto"><code>notepad.open(i.rstrip())</code></p>
]]></description><link>https://community.notepad-plus-plus.org/post/64303</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64303</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Wed, 24 Mar 2021 13:39:47 GMT</pubDate></item><item><title><![CDATA[Reply to Python script plugin console to open multiple files on Wed, 24 Mar 2021 13:38:41 GMT]]></title><description><![CDATA[<p dir="auto">I confirmed:</p>
<pre><code>&gt;&gt;&gt; n = 'C:/Users/peter.jones/Downloads/TempData/nppCommunity/\xd0\x9f\xd0\xbe\xd0\xb3\xd1\x80\xd1\x83\xd0\xb7\xd1\x87\xd0\xb8\xd0\xba.mtl'
&gt;&gt;&gt; notepad.open(n)
</code></pre>
<p dir="auto">opened the file just fine, but</p>
<pre><code>&gt;&gt;&gt; n = 'C:/Users/peter.jones/Downloads/TempData/nppCommunity/\xd0\x9f\xd0\xbe\xd0\xb3\xd1\x80\xd1\x83\xd0\xb7\xd1\x87\xd0\xb8\xd0\xba.mtl\n'
&gt;&gt;&gt; notepad.open(n)
</code></pre>
<p dir="auto">shows<br />
<img src="/assets/uploads/files/1616593093707-ab58e9fc-7261-40b6-9904-fb867a4e7265-image.png" alt="ab58e9fc-7261-40b6-9904-fb867a4e7265-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">Notice the newline between <code>.mtl</code> and the end-quote <code>"</code></p>
]]></description><link>https://community.notepad-plus-plus.org/post/64302</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64302</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Wed, 24 Mar 2021 13:38:41 GMT</pubDate></item><item><title><![CDATA[Reply to Python script plugin console to open multiple files on Wed, 24 Mar 2021 13:33:52 GMT]]></title><description><![CDATA[<p dir="auto">Ah, <a class="plugin-mentions-user plugin-mentions-a" href="/user/ekopalypse" aria-label="Profile: Ekopalypse">@<bdi>Ekopalypse</bdi></a> showed it working with the name represented with the \x## notation, so that doesn’t appear to be the problem.  I then think it’s the newline sequence at the end of your text line, because the real filename doesn’t end in newline.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/64300</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64300</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Wed, 24 Mar 2021 13:33:52 GMT</pubDate></item><item><title><![CDATA[Reply to Python script plugin console to open multiple files on Wed, 24 Mar 2021 13:32:30 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/june-wang" aria-label="Profile: June-Wang">@<bdi>June-Wang</bdi></a> said in <a href="/post/64294">Python script plugin console to open multiple files</a>:</p>
<blockquote>
<p dir="auto">I can open it using notepad.open(‘F:/06__Other_Models/Transport/round1/convert2/58542_Погрузчик.mtl’).  But from python console using above code, notepad++ keeps saying ‘File F:/06__Other_Models/Transport/round1/convert2/58542_Погрузчик.mtl doesn’t exist’, I think it has something to do with the non UTF-8 encoded file(names).</p>
</blockquote>
<p dir="auto">Actually, <code>\xd0\x9f</code> <em>is</em> the two-byte sequence to represent <code>П</code> in UTF-8.  However, it may be that there is an encoding/decoding trick that you need to take in Python to convert the raw UTF-8 bytes read from the file to translate to the valid pathname.  I’m not an expert on Python+encoding.</p>
<p dir="auto">However, I see one more problem: <code>.mtl\n'</code>: because you read the line from a newline-delimited file, you still have a newline in each line.  You should really remove the trailing newline sequence before passing it to the <code>notepad.open()</code> command.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/64299</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64299</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Wed, 24 Mar 2021 13:32:30 GMT</pubDate></item><item><title><![CDATA[Reply to Python script plugin console to open multiple files on Wed, 24 Mar 2021 13:28:48 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/june-wang" aria-label="Profile: June-Wang">@<bdi>June-Wang</bdi></a></p>
<p dir="auto">Which version of  PS plugin are you using?</p>
<p dir="auto"><img src="/assets/uploads/files/1616592515263-e79a9cf9-27d0-48d2-a1e1-6fa9c9f43622-image.png" alt="e79a9cf9-27d0-48d2-a1e1-6fa9c9f43622-image.png" class=" img-fluid img-markdown" /></p>
]]></description><link>https://community.notepad-plus-plus.org/post/64297</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64297</guid><dc:creator><![CDATA[Ekopalypse]]></dc:creator><pubDate>Wed, 24 Mar 2021 13:28:48 GMT</pubDate></item></channel></rss>