Returns file names that match a search pattern in a specified path, and optionally searches subdirectories.
Imports System.IO
Imports System.Xml.Linq
Module Module1
Sub Main()
Try
Dim files = From chkFile In Directory.EnumerateFiles("c:\", "*.txt", _
SearchOption.AllDirectories)
From line In File.ReadLines(chkFile)
Where line.Contains("aaa")
Select New With {.curFile = chkFile, .curLine = line}
For Each f In files
Console.WriteLine("{0}\t{1}", f.curFile, f.curLine)
Next
Console.WriteLine("{0} files found.", _
files.Count.ToString())
Catch PathEx As Exception
Console.WriteLine(PathEx.Message)
End Try
End Sub
End Module
Related examples in the same category