Hey,
I have a piece of code which seems to do an exact search. I have tried to change it so that it retrieves all files that have some part of the search topic in their name. So if i search by "Hello" I would receive a file called and "Hello", "Hello World" and also "Everybody say Hello". Can anyone help me change my search to do this apposed to just lloking for an exact phrase? My current code is;
Code:Private Sub SearchForFiles(ByVal StartDir As String) Dim DirPath As String = Path.GetDirectoryName(StartDir) Dim FilePattern As String = Path.GetFileName(StartDir) FilePattern = "*" & FilePattern & "*" Dim TotalFiles As Integer = 0 lstResults.Items.Clear() If Directory.Exists(DirPath) Then Dim di As New DirectoryInfo(DirPath) Dim fi() As FileInfo = di.GetFiles(FilePattern, SearchOption.AllDirectories) For Each f As FileInfo In fi lstResults.Items.Add(f.FullName) TotalFiles += 1 Next Else lstResults.Items.Add("Invalid Start Directory") End If lstResults.Items.Add("Total Files = " & TotalFiles.ToString()) End Sub Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Clic txtSearch.Text = "C:\Hello\" & txtSearch.Text & ".*" SearchForFiles(txtSearch.Text.Trim()) End Sub




Reply With Quote