tags:

views:

105

answers:

2

Hi,

please help me with following programming exercise..

Lets say I have a text file MyFile.txt with following content

hellosam whatsup mynameisjohn ...

I want to go through each word in MyFile.txt and then see which file in my local folder c:\myfolders\myallfiles contain that word.

For example, I want to see which file would contain reference to hellosam and so on so forth.

+1  A: 

This post by Derik Whittaker will be useful for you.

Perpetualcoder
I was going to post an answer, it took literally 30 seconds to write the 3 lines of code, but it's homework and you've given enough clues :)
Si
+2  A: 

probably something similiar to this... this is more psuedo-code. Its more fun to figure the rest out yourself.

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;
        }
    }
Ryan Bennett