Find multiple strings in a directory
Francisco Simarro last edited by Francisco Simarro
I have one file with different strings, separate strings and we would like to find the name of the file that appear each file (all the files are in one directory). For example: I have one directory with the following file names , File1, file2, File3, file4. and in another file I have the following strings:
String1, string2, string3.
string 1 appear in the file1,file2.
String 2 appear in the file2,file4.
If were needed any clarification , I will do it.
How I can do this action with notepad automatically?
Alan Kilborn last edited by
I am by no means clear on your need, but it seems like you want to use data from a file as a source for your search. Meaning to successively put a string on a line in your file logically into the Find what box in Notepad++, run the search, go onto the next string, etc.
This cannot be achieved in Notepad++ itself.
However, if you add a scripting plugin, then you can basically do whatever logic you can code up.
I’m sure this kind of thing has come up before; maybe some searching of old postings will find a solution that meets your need…
@Alan-Kilborn , Thank for your quickly reply.
Sorry, I will try to explain better.
I have one file with the following content
I have one directory, C:temp, with several .xml files, File1, file2, File3, file4.
I have to find in which files the character strings appear, showing me the name of the file and not searching manually string by string.
Example of result:
string1 appear File2,file3
string3 appear File4
string2 appear File1,file3
Is there any plugin to do this action automatically?
Alan Kilborn last edited by Alan Kilborn
I think your clarification just solidified that what I supposed was what you wanted.
There is no plugin to do that.
However, as I mentioned before, a scripting plugin will give you such capability, with a bit of work added.
There are some similar ideas to that in THIS THREAD that could be a starting point for your desired task.
Also, there is no real reason for having your task run via Notepad++. Any programming language could do it equally as well, not involving Notepad++ at all.
@Alan-Kilborn thanks for your quickly response again
The problem is that I’m not familiar with Notepad ++ scripting and I don’t how I can start it.
PeterJones last edited by PeterJones
This isn’t a free code-writing service. This isn’t a programming-for-hire. And it’s not a discussion forum for general programming techniques. This Forum is about Notepad++: the literal answer of “Can Notepad++ take a list of terms from one file, and use that list to search a directory” is “no”; or the slightly more descriptive answer is, “not natively; if you are willing to use a scripting plugin, and if you are willing to create said script, then it can be done, but that’s not something you should expect a Community of Notepad++ users to do for you.”
But instead of ending with a “no”, he at least pointed you to a script that did something similar, giving you a place to start. You seem to have chosen to not accept that as a start (based on your “I don’t know how I can start it”), which might mean that you don’t have the skills necessary even with that giant hint. But assuming that you do have more skills than you think you do, I will give you a few more places to start, if that one script wasn’t sufficient for you.
And as he pointed out, there have been other scripts published in this forum in the past that probably come even closer (ie, they read the contents of one file to decide what to search for in another) – if you search the forum you might found some of them. For example, searching for “PythonScript replacements in second file” – two of the four most recent hits have scripts that are even closer to what you want. (I went with “replacements” instead of “search”, because honestly, most of the people who have this kind of question really want to edit the matched files, not just list them. But if the code has the logic to replace, it has the logic to just find, with just a tiny bit of effort on your part. And if you aren’t willing to put in that effort, then such a solution isn’t something for you anyway.)
He also pointed out that you could just use a programming language and do it without Notepad++. But such programs are off-topic for a Notepad++ forum.
And there are plenty of command-line tools that could be combined to read the one file line by line, and use the results of that to search the directory for each of the lines of that one file (for example, the Windows cmd.exe’s
forcommand can loop on the contents of a file, putting each line in a command-line variable; then using that variable in the command that
forruns, like a cmd.exe
findcommand or cmd.exe
findstrcommand, or you could download a windows version of linux
grep, even more powerful). But those are not Notepad++ tools, and are off topic here (though my links should provide you with enough to discover it on your own). (or, you can use one of Notepad++'s menus to find the cheater solution in the following apparently-nonsense string:
Zm9yIC9GICVYIElOIChsaXN0ZmlsZS50eHQpIERPIGZpbmQgL24gIiVYIiBzZWFyY2hkaXJcKg– I’ll give you a hint: the menu entry has “decode” in the name)
But posting every six hours here, hoping you can convince someone to do your job (or hobby) for free by annoying us sufficiently, seems like it’s a tactic likely to fail and probably even backfire.
I hope you are willing to put in the effort to solve it, given the huge hints already given to you. Good luck.
Thanks for your clarification. Sorry for to present the question in this forum.