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
variableNumber1 variableNumber2 variableNumber3 variableNumber4
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="" /> </Macro>
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 ofPath2
in all*.c
and*.h
files for the search terms stored (line by line) in fileSearchTerms.txt
atPath1
.When you add option
/r
, you can use the basic regular expression support (seefindstr /?
) of FindStr to write your search terms.When you add option
/i
, you can search case-insensitive. -
Hello, @arhack-bifrost, @Dinkumoil and All,
I was away from the N++ community since more than a month ( see my post below )
https://community.notepad-plus-plus.org/post/47895
So, my reply may be out of date !
However, the macro, below, with
2
almost identical parts, is able to first searches, recursively, for the expressionvariableNumber1
in all the files of your Folder_Path. Secondly, it searches, in the same way, for the expressionvariableNumber2
and, finally, shows the2
successive search operations, in theFind Result
panel :-))<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="X:\The_path_of_MyFolder\" /> <Action type="3" message="1652" wParam="0" lParam="0" sParam="*.c" /> <Action type="3" message="1702" wParam="0" lParam="800" sParam="" /> <Action type="3" message="1701" wParam="0" lParam="1656" sParam="" /> <Action type="3" message="1700" wParam="0" lParam="0" sParam="" /> <Action type="3" message="1601" wParam="0" lParam="0" sParam="variableNumber2" /> <Action type="3" message="1625" wParam="0" lParam="2" sParam="" /> <Action type="3" message="1653" wParam="0" lParam="0" sParam="X:\The_path_of_MyFolder\" /> <Action type="3" message="1652" wParam="0" lParam="0" sParam="*.c" /> <Action type="3" message="1702" wParam="0" lParam="800" sParam="" /> <Action type="3" message="1701" wParam="0" lParam="1656" sParam="" /> </Macro>
Notes :
-
Of course, you may add as many sections as you want to perform other searches ;-))
-
The parameters value
800
means :512
( Direction = Down ) +256
( Wrap around ) +32
= Search in sub-folders
Two important remarks :
- Your initial macro, in your post, contains a syntax error. Indeed, the line :
<Action type="3" message="1652" wParam="0" lParam="0" sParam="*.c*"" />
should be :
<Action type="3" message="1652" wParam="0" lParam="0" sParam="*.c" />
- Secondly, note that, in all caases, the absolute folder path, let’s say
"X:\The_path_of_MyFolder\"
, must, necessarily, ends with a backslash symbol (\
)
Cheers,
guy038
-