For small directory size code is working fine ,it gives this error message when size of directory files are big.
My code :
IEnumerable text
I would use Directory.EnumerateFiles
and File.ReadLines since they are less memory hungry, they are working like a StreamReader
whereas Directory.GetFiles
and File.ReadAllLines
reads all into memory first:
var matchingLines = Directory.EnumerateFiles(@"C:\Users\karansha\Desktop\watson_query\", "*.*")
.SelectMany(fn => File.ReadLines(fn))
.Where(l => l.IndexOf("appGUID: null", StringComparison.InvariantCultureIgnoreCase) >= 0);
foreach (var line in matchingLines)
{
Regex regex = new Regex(@"User:\s*(?[^\s]+)");
// etc pp ...
}
You also don't need to create the List
for all the lines again. Just enumerate the query with foreach
(textLines.ToList
creates a third collection which is also redundant).