EDN Admin
Well-known member
Im trying to make a script that searches for multiple .TXT files in a directory, and then searches the text of each file for a matching string(ie. "turtles"). It will search each file for the word "turtles". Ive been on google trying to figure this out
for a while, Im guessing StreamReader is the way to go? Not sure. Thanks.
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Private <span style="color:Blue; Sub Button2_Click(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles Button2.Click
<span style="color:Blue; Dim l_Dir <span style="color:Blue; As IO.DirectoryInfo
l_Dir = <span style="color:Blue; New IO.DirectoryInfo(MyPath)
<span style="color:Blue; For <span style="color:Blue; Each l_File <span style="color:Blue; As IO.FileInfo <span style="color:Blue; In l_Dir.GetFiles
<span style="color:Blue; If l_File.Extension.ToUpper = <span style="color:#A31515; ".TXT" <span style="color:Blue; Then
<span style="color:Green; Heres where Im at now
<span style="color:Blue; Dim FILE_NAME <span style="color:Blue; As <span style="color:Blue; String = MyPath & l_File.ToString
<span style="color:Blue; Dim objReader <span style="color:Blue; As <span style="color:Blue; New System.IO.StreamReader(FILE_NAME)
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; Next
<span style="color:Blue; End <span style="color:Blue; Sub
[/code]
View the full article
for a while, Im guessing StreamReader is the way to go? Not sure. Thanks.
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Private <span style="color:Blue; Sub Button2_Click(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles Button2.Click
<span style="color:Blue; Dim l_Dir <span style="color:Blue; As IO.DirectoryInfo
l_Dir = <span style="color:Blue; New IO.DirectoryInfo(MyPath)
<span style="color:Blue; For <span style="color:Blue; Each l_File <span style="color:Blue; As IO.FileInfo <span style="color:Blue; In l_Dir.GetFiles
<span style="color:Blue; If l_File.Extension.ToUpper = <span style="color:#A31515; ".TXT" <span style="color:Blue; Then
<span style="color:Green; Heres where Im at now
<span style="color:Blue; Dim FILE_NAME <span style="color:Blue; As <span style="color:Blue; String = MyPath & l_File.ToString
<span style="color:Blue; Dim objReader <span style="color:Blue; As <span style="color:Blue; New System.IO.StreamReader(FILE_NAME)
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; Next
<span style="color:Blue; End <span style="color:Blue; Sub
[/code]
View the full article