<?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[Execute N++ &quot;Find in Files&quot; via cmdline&#x2F;script?]]></title><description><![CDATA[<p dir="auto">Love the product, but curious to know if it is possible to execute the “Find in Files” from the command-line / batch / vbscript.</p>
<p dir="auto">The output seen within N++ is something I like and I’d like to incorporate this output for some automated tasks if possible.</p>
<p dir="auto">Cheers, Cam.</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/14181/execute-n-find-in-files-via-cmdline-script</link><generator>RSS for Node</generator><lastBuildDate>Sat, 06 Jun 2026 10:17:37 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/14181.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 20 Jul 2017 10:31:07 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Execute N++ &quot;Find in Files&quot; via cmdline&#x2F;script? on Mon, 04 Dec 2023 17:25:49 GMT]]></title><description><![CDATA[<p dir="auto">This is a real necropost at roughly 6.5 years later, but I wanted to post an updated version of the earlier script made by <a class="plugin-mentions-user plugin-mentions-a" href="/user/scott-sumner" aria-label="Profile: Scott-Sumner">@<bdi>Scott-Sumner</bdi></a> ; one that just feels a bit less hackish (sorry).</p>
<p dir="auto">I call this variation <code>SearchResultPanelGetText.py</code>:</p>
<pre><code class="language-py"># -*- coding: utf-8 -*-
from __future__ import print_function

#########################################
#
#  SearchResultPanelGetText (SRPGT)
#
#########################################

# references:
#  https://community.notepad-plus-plus.org/topic/14181
#  for newbie info on PythonScripts, see https://community.notepad-plus-plus.org/topic/23039/faq-desk-how-to-install-and-run-a-script-in-pythonscript

#-------------------------------------------------------------------------------

from ctypes import ( create_unicode_buffer, WinDLL, WINFUNCTYPE, )
from ctypes.wintypes import ( BOOL, HWND, LPARAM, )
import re

user32 = WinDLL('user32')

#-------------------------------------------------------------------------------

class SRPGT(object):

    def __init__(self):
        self.search_results_hwnd = None
        WNDENUMPROC = WINFUNCTYPE(BOOL, HWND, LPARAM)
        user32.EnumChildWindows(user32.FindWindowW(u'Notepad++', None), WNDENUMPROC(self.foreach_child_window), 0)

    def foreach_child_window(self, hwnd, __):
        length = user32.GetWindowTextLengthW(hwnd)
        if length &gt; 0:
            buff = create_unicode_buffer(length + 1)
            user32.GetWindowTextW(hwnd, buff, length + 1)
            if re.match(r'(?:Search) ".*?" \(\d+ hits? in \d+ files? of \d+ searched', buff.value):
                self.search_results_hwnd = hwnd
                return False  # stop searching windows
        return True  # continue searching windows

    def get_text(self):
        search_results_complete_text = ''
        if self.search_results_hwnd is not None:
            length = user32.GetWindowTextLengthW(self.search_results_hwnd)
            if length &gt; 0:
                buff = create_unicode_buffer(length + 1)
                user32.GetWindowTextW(self.search_results_hwnd, buff, length + 1)
                search_results_complete_text = buff.value
        return search_results_complete_text

    def get_most_recent_search_result_text(self):
        recent_text = ''
        m = re.match(r'(?s)(?:Search) ".*?" \(\d+ hits? in \d+ files? of \d+ searched.*?(?=^Search|\Z)', self.get_text())
        if m: recent_text = m.group(0)
        return recent_text

#-------------------------------------------------------------------------------

if __name__ == '__main__': print(SRPGT().get_text())  # demo
</code></pre>
]]></description><link>https://community.notepad-plus-plus.org/post/90935</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/90935</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Mon, 04 Dec 2023 17:25:49 GMT</pubDate></item><item><title><![CDATA[Reply to Execute N++ &quot;Find in Files&quot; via cmdline&#x2F;script? on Fri, 21 Jul 2017 17:09:36 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/scott-sumner" aria-label="Profile: Scott-Sumner">@<bdi>Scott-Sumner</bdi></a></p>
<p dir="auto">in general yes, but not for the moment, currently I’m doing 3 projects in parallel<br />
And I don’t see that this progresses. :-)</p>
<p dir="auto">Cheers<br />
Claudia</p>
]]></description><link>https://community.notepad-plus-plus.org/post/25791</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/25791</guid><dc:creator><![CDATA[Claudia Frank]]></dc:creator><pubDate>Fri, 21 Jul 2017 17:09:36 GMT</pubDate></item><item><title><![CDATA[Reply to Execute N++ &quot;Find in Files&quot; via cmdline&#x2F;script? on Fri, 21 Jul 2017 12:24:58 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/claudia-frank" aria-label="Profile: Claudia-Frank">@<bdi>Claudia-Frank</bdi></a></p>
<blockquote>
<p dir="auto">python_automation_api_for_npp</p>
</blockquote>
<p dir="auto">Maybe not an all-encompasing automation API, but one focused on the ever-controversial Find functionality…<br />
Are you up for a joint project with me on this?<br />
:-D</p>
]]></description><link>https://community.notepad-plus-plus.org/post/25785</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/25785</guid><dc:creator><![CDATA[Scott Sumner]]></dc:creator><pubDate>Fri, 21 Jul 2017 12:24:58 GMT</pubDate></item><item><title><![CDATA[Reply to Execute N++ &quot;Find in Files&quot; via cmdline&#x2F;script? on Thu, 20 Jul 2017 21:09:38 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/scott-sumner" aria-label="Profile: Scott-Sumner">@<bdi>Scott-Sumner</bdi></a></p>
<p dir="auto">nice one and could be already half the solution. :-)<br />
Maybe we should think about python_automation_api_for_npp ;-)</p>
<p dir="auto">Cheers<br />
Claudia</p>
]]></description><link>https://community.notepad-plus-plus.org/post/25771</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/25771</guid><dc:creator><![CDATA[Claudia Frank]]></dc:creator><pubDate>Thu, 20 Jul 2017 21:09:38 GMT</pubDate></item><item><title><![CDATA[Reply to Execute N++ &quot;Find in Files&quot; via cmdline&#x2F;script? on Thu, 20 Jul 2017 20:11:50 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/claudia-frank" aria-label="Profile: Claudia-Frank">@<bdi>Claudia-Frank</bdi></a></p>
<p dir="auto">I also am not sure what <a class="plugin-mentions-user plugin-mentions-a" href="/user/cameron-young" aria-label="Profile: Cameron-Young">@<bdi>Cameron-Young</bdi></a> is really wanting to do, but it got me to thinking about how to handle <strong>Find-in-Files</strong> output programmatically <em>“within”</em> Notepad++ via Pythonscript.</p>
<p dir="auto">I came up with the following that will get the textual contents of the <strong>Find result</strong> panel (based upon the code ideas <a href="https://notepad-plus-plus.org/community/topic/14130/hide-or-toggle-find-results-panel-with-keyboard-command" title="https://notepad-plus-plus.org/community/topic/14130/hide-or-toggle-find-results-panel-with-keyboard-command" rel="nofollow ugc">here</a>–a pretty shallow rip-off in fact!).  This could be prefaced with setting the <strong>Find</strong> dialog’s control fields and pressing the <strong>Find-in-Files</strong> (or <strong>Find-All-…</strong>) button (pressing a button example <a href="https://notepad-plus-plus.org/community/topic/13754/replace-1-lines" title="https://notepad-plus-plus.org/community/topic/13754/replace-1-lines" rel="nofollow ugc">here</a>) under program control.  Once you have the output text, it can be parsed at will to do whatever is needed from that.</p>
<p dir="auto">Here’s <code>FindResultPanelGetText.py</code>:</p>
<pre><code>import ctypes
from ctypes.wintypes import BOOL, HWND, LPARAM
WNDENUMPROC = ctypes.WINFUNCTYPE(BOOL, HWND,LPARAM)
FindWindow = ctypes.windll.user32.FindWindowW
GetWindowText = ctypes.windll.user32.GetWindowTextW
GetWindowTextLength = ctypes.windll.user32.GetWindowTextLengthW
EnumChildWindows = ctypes.windll.user32.EnumChildWindows
GetClassName = ctypes.windll.user32.GetClassNameW
curr_class = ctypes.create_unicode_buffer(256)

find_result_panel_complete_text = ''

def foreach_window(hwnd, lParam):
    global find_result_panel_complete_text
    length = GetWindowTextLength(hwnd)
    if length &gt; 0:
        buff = ctypes.create_unicode_buffer(length + 1)
        GetWindowText(hwnd, buff, length + 1)
        if buff.value.startswith('Search "'):  # perhaps change to more rigorous test...
            find_result_panel_complete_text = buff.value
            return False
    return True

EnumChildWindows(FindWindow(u'Notepad++', None), WNDENUMPROC(foreach_window), 0)
editor.copyText(find_result_panel_complete_text)  # result in clipboard
</code></pre>
]]></description><link>https://community.notepad-plus-plus.org/post/25762</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/25762</guid><dc:creator><![CDATA[Scott Sumner]]></dc:creator><pubDate>Thu, 20 Jul 2017 20:11:50 GMT</pubDate></item><item><title><![CDATA[Reply to Execute N++ &quot;Find in Files&quot; via cmdline&#x2F;script? on Thu, 20 Jul 2017 14:04:23 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/cameron-young" aria-label="Profile: Cameron-Young">@<bdi>Cameron-Young</bdi></a></p>
<p dir="auto">not 100% sure what you want to achieve.</p>
<p dir="auto">Do you have some automated tasks while npp is not running at all<br />
and at some step you do want to search something in files and the<br />
output should be similar to the one npp shows</p>
<p dir="auto">or</p>
<p dir="auto">do you have npp running, do something and then you want to run<br />
find in files dialog and this output should be forwarded to<br />
some automated task?</p>
<p dir="auto">Maybe you wanna describe in more detail what exactly you want to do.</p>
<p dir="auto">Cheers<br />
Claudia</p>
]]></description><link>https://community.notepad-plus-plus.org/post/25744</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/25744</guid><dc:creator><![CDATA[Claudia Frank]]></dc:creator><pubDate>Thu, 20 Jul 2017 14:04:23 GMT</pubDate></item></channel></rss>