Iterate through a list of words and search a folder to search for files (s) containing that word

Let's say I have a text file MyFile.txt with the following contents:

hellosam
whatsup
mynameisjohn
etc...

I want to look at every word in MyFile.txt, and then see which file in my local folder C: \ myfolders \ myallfiles contains this word.

For example, I want to see which file will contain a link to hellosam, etc. etc.

+3
source share
1 answer

maybe something like this ... this is more psuedo-code. Its more interesting to portray the rest.

string[] files = Directory.GetFiles("directorypath");

    foreach (string s in files)
    {
        FileInfo file = new FileInfo(s);
        StreamReader reader = file.OpenText();

        if(reader.ReadToEnd().Contains("string you are looking for"))
        {
            return true;
        }
    }
+2
source

Source: https://habr.com/ru/post/1725364/


All Articles