public static List<string> SearchStringInTextFiles(string pfad, string search)
{
List<string> matchFiles = new List<string>();
if (search != "")
{
string pattern = search;
string[] metaChars = new string[] { @"\", @"*", @"+", @"?", @".", @"(", @")", @"[", @"]", @"{", @"}", @"/", @"|", @"^", @"$" };
foreach (string s in metaChars)
{
pattern = pattern.Replace(s, @"\" + s);
}
foreach (string fileName in Directory.GetFiles(pfad, "*.txt", SearchOption.AllDirectories))
{
string[] lines = File.ReadAllLines(fileName);
if (lines.Length > 0)
{
if (System.Text.RegularExpressions.Regex.IsMatch(String.Join(Environment.NewLine, lines), pattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase))
{
matchFiles.Add(fileName);
}
}
}
}
return matchFiles;
}