Hi all
This sounds easy and I'm sure it is but i'm just having so much trouble. I have a directory with text files. I want to search the text files for a string and return the name of the file that containes the string. I've tried various way below ut unsuccessfully. Please could someone take a look and offer some assistance?
thanks
-
-
string directory = @"D:\SearchFolder";
-
DirectoryInfo dirinfo = new DirectoryInfo(directory);
-
-
FileInfo[] files = dirinfo.GetFiles("EE*.PRN");
-
-
foreach (FileInfo i in files)
-
{
-
List<string> lines = File.ReadAllLines(i.ToString().ToList());
-
foreach (string line in lines)
-
{
-
if (line.Contains("UNIQUESTRING"))
-
textBox2.Text += i + "contains" + line.ToString() + Environment.NewLine;
-
}
-
-
//Regex.Match(i, "UNIQUESTRING");
-
//if (Regex.Match(i, "UNIQUESTRING"))
-
//{
-
// MessageBox.Show("File with regex is : " + i);
-
//}
-
-
//string ex = null;
-
//ex = (from line in File.ReadAllLines(i)
-
// where line == "UNIQUESTRING"
-
// select line).ToString();
-
-
}
-