OK I am trying to get this to work.
I am looking for a code snippit that searches the files in a specified directory for text that is inputed by the user then adds the files that contain that text to a list box
any help will be appreciated
Printable View
OK I am trying to get this to work.
I am looking for a code snippit that searches the files in a specified directory for text that is inputed by the user then adds the files that contain that text to a list box
any help will be appreciated
try this:
vb Code:
For Each file As String In IO.Directory.GetFiles("directory path", "*.txt") Dim lines() As String = IO.File.ReadAllLines(file) For x As Integer = 0 To lines.GetUpperBound(0) If lines(x).Contains(TextBox1.Text) Then Debug.Print(file) End If Next Next Debug.Print("done")
this might be slightly better:
vb Code:
For Each file As String In IO.Directory.GetFiles("directory path", "*.txt") Dim fileText As String = IO.File.ReadAllText(file) If fileText.Contains(TextBox1.Text) Then Debug.Print(file) End If Next Debug.Print("done")
ok thx i moded this to do what i needed it to do thank you