hey guys.
i've got a problem. my program that i've coded doesn't work. normally it should loop through a folder and its subfolders and find special filetypes. this part works. but i also have a method, which reads a file und tries to find a special word. unfortunately this part doesn't work. i've got no idea why! i've tried a lot, but nothing was successful. the filetypes: *.html, *.htm, *.txt, *.js.
here's my code, perhaps you'll find the mistake.
i hope you'll be able to help me.
thx
i've got a problem. my program that i've coded doesn't work. normally it should loop through a folder and its subfolders and find special filetypes. this part works. but i also have a method, which reads a file und tries to find a special word. unfortunately this part doesn't work. i've got no idea why! i've tried a lot, but nothing was successful. the filetypes: *.html, *.htm, *.txt, *.js.
here's my code, perhaps you'll find the mistake.
Code:
Public Function GetFiles(ByVal path As String, ByVal Pattern As String, ByRef arr As ArrayList)
arr.AddRange(IO.Directory.GetFiles(path, Pattern))
Dim s As String
For Each s In IO.Directory.GetDirectories(path)
GetFiles(s, Pattern, arr)
Next
Return arr
End Function
Public Sub Search()
Dim sr As IO.StreamReader
Dim fw As New StreamWriter(_textSearch, True)
Dim s As String
Dim r As System.Text.RegularExpressions.Regex
Dim searchWord As String
Dim matches As Integer
For q = 0 To typeArray.Count - 1
Dim arr As New ArrayList()
GetFiles(_folder, typeArray.Item(q), arr)
Dim f As String
For Each f In arr
Try
sr = New IO.StreamReader(f)
s = sr.ReadToEnd
sr.Close()
searchWord = "http"
r = New System.Text.RegularExpressions.Regex(searchWord)
matches = r.Matches(s).Count
If matches > 0 Then
fw.WriteLine(f + " - hits: " + matches.ToString)
End If
s = String.Empty
Catch ex As Exception
fw.WriteLine("following error accured by trying to read the file " & f _
& ": " & ex.Message)
End Try
Next
If matches = 0 Then
fw.WriteLine("nothing found")
End If
Next
End Sub
i hope you'll be able to help me.
thx