How to do multiple search for a list of strings

  • I have a list of strings and I want to search for each one of them [separately] in all files (*.c or *.h) automaticaly inside a folder for example


    and results will be something like that (with every file where it is found)

    Search “variableNumber4” (34 hits in 4 files)
    Search “variableNumber3” (6 hits in 5 files)
    Search “variableNumber2” (7 hits in 6 files)
    Search “variableNumber1” (4 hits in 1 files)
    I tried a macros recording the action “search in file” I save it and then went to the code behinde and I found the following

    <Macro name="searchTest" Ctrl="no" Alt="no" Shift="no" Key="0">
                <Action type="3" message="1700" wParam="0" lParam="0" sParam="" />
                <Action type="3" message="1601" wParam="0" lParam="0" sParam="variableNumber1" />
                <Action type="3" message="1625" wParam="0" lParam="2" sParam="" />
                <Action type="3" message="1653" wParam="0" lParam="0" sParam="the_path_of_MyFolder" />
                <Action type="3" message="1652" wParam="0" lParam="0" sParam="*.c*"" />
                <Action type="3" message="1702" wParam="0" lParam="32" sParam="" />
                <Action type="3" message="1701" wParam="0" lParam="1656" sParam="" />

    in action number “1601” the sParam is varaibleNumber1 that means each time I run the macro I’m getting all the time resulats for “variableNumber1”

  • @Oussama-Moustakim

    This task needs a scripting solution, i.e. you need to install a scripting plugin like PythonScript, LuaScript or NppExec and write some code.

    Alternatively you could use the console FindStr command as long as your search terms and the files to be searched contain only characters from the 7 bit ASCII code page (character codes up to 127). You can use the following command

    findstr /s /g:"<Path1>\SearchTerms.txt" "<Path2>\*.c" "<Path2>\*.h"

    to search recursively (option /s) in all subfolders of Path2 in all *.c and *.h files for the search terms stored (line by line) in file SearchTerms.txt at Path1.

    When you add option /r, you can use the basic regular expression support (see findstr /?) of FindStr to write your search terms.

    When you add option /i, you can search case-insensitive.

Log in to reply