Batch automate "Find in Files"



  • Hey guys, loving the community sofar.

    So here is my question:

    I have a text file containing a list of filenames that looks like this:

    filenameA
    filenameB
    filenameC

    What I want to do is to use Notepad++ “find in files” to search a certain directory for filenameA then search filenameB and so on…
    My end goal is to identify which files returend 0 results.

    Any ideas how to solve this problem? I tried to write a script with PythonScript but I couldn’t find anything in the documentation about “find in files”. Thank you in advance.



  • @Hasso-Falisco

    Find-in-files is a Notepad++ feature; the Pythonscript paradigm is more focused on single-document (Scintilla) access. You can see this in the documentation by noticing how many editor. xxx() functions there are versus how many notepad. xxx() functions there are.

    Pythonscript provides two valuable find-related functions: editor.research() and editor.rereplace() . You task needs would presume more interest in the search function. These functions work on a single Notepad++ edit buffer (the currently active tab window), so if you want to deal with multiple documents you have to change the active document yourself (notepad.activateFile()) before searching.

    Overall it is not difficult…but it is not a simple single function call either…

    Another option is to skip Pythonscript for this and go with straight Python, since you hint that you know Python, and nothing in your problem description talks about manipulating text in an open edit buffer (which Pythonscript is adept at). However, it is very much still a “bunch of steps” solution in straight Python as well.



  • @Hasso-Falisco

    Suppose you have a file named FilesToFind.txt that contains:

    filenameA
    filenameB
    filenameC
    

    Open a command window in the directory you want to search. Then enter this command:

    for /F %F in ('type FilesToFind.txt') do @dir /b %F
    

    If you also want to search in sub-directories, use:

    for /F %F in ('type FilesToFind.txt') do @dir /s /b %F
    

    That will spit out a list of the files that exist, which you may be able to use effectively.