string directory = @"D:\Zen\_scripts";
string filespattern = "*.cs";
string searchstring = "lock";
var searchregex = new System.Text.RegularExpressions.Regex(searchstring, System.Text.RegularExpressions.RegexOptions.Compiled);
var filelist = System.IO.Directory.GetFiles(directory, filespattern, System.IO.SearchOption.AllDirectories).ToList();
for(int i=0; i < filelist.Count; i++){
bool isfound = false;
using (var streamReader = new System.IO.StreamReader(filelist[i], true)){
while (streamReader.Peek() > 0){
string line = streamReader.ReadLine();
if (searchregex.IsMatch(line)){
isfound = true;
break;
}
}
}
if(!isfound)
filelist.RemoveAt(i--);
}
return string.Join("\n", filelist.ToArray());