Reputation: 480
I am trying to make a simple search engine that will search for a pattern in a file name e.g. a number that is a part of a file name. So far it only searches for the exact string e.g. o2.url
, but I have o21.url
and o22.url
in the same folder and I would like to be able to have those in my search results. I want to ask is there any way of modifying this code to achieve that.
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
For Each foundFile As String In My.Computer.FileSystem.GetFiles(
"C:\Users\GrzegoP\Desktop\xxx", Microsoft.VisualBasic.FileIO.SearchOption.SearchAllSubDirectories, Text1.Text & ".url")
List1.Items.Add(foundFile)
Next
End Sub
End Class
Any suggestions?
Thanks.
Upvotes: 0
Views: 332
Reputation:
You can add the "*" wildcard:
My.Computer.FileSystem.GetFiles(
"C:\Users\GrzegoP\Desktop\xxx", Microsoft.VisualBasic.FileIO.SearchOption.SearchAllSubDirectories, "*" & Text1.Text & "*" & ".url")
This code finds any file, with the .url extension, including Text1.Text
in any part of its name.
Upvotes: 2