Link to home
Start Free TrialLog in
Avatar of jsctechy
jsctechyFlag for United States of America

asked on

how to search a file base on the name but not the extansion

hi,
this one is not too bad, I need to search for a file in a given directory without consider its extension. For instance i'm looking for a file called test and i need to search on directory C:\Temp\ but on that directory there are 4 files showing the word test like this:

Test.txt
Another_Test.doc
My_Test.pdf
Their_Test.mdb

so every file that match that keyword Test should be add it to my listbox1. How can i do my search?
Thanks for your input
jsctechy
SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Try something like this
        Dim path As String = "c:\temp\"
        Dim searchPattern As String = "test"
        Dim FileList() As String = IO.Directory.GetFiles(path, String.Concat("*", searchPattern, "*"))
        Me.ListBox1.Items.AddRange(FileList)

Open in new window

Avatar of jsctechy

ASKER

ipaulino,
you are close one thing though i dont need the whole path added to the listbox1. another thing it only display two files when there are 4 files with the search pattern
i need the path for later but no display it on the listbox1
Try this update
        Dim path As String = "c:\temp\"
        Dim searchPattern As String = "test"
        Dim total As Integer = 0
        Dim FileList() As String = IO.Directory.GetFiles(path, String.Concat("*", searchPattern, "*"))
        For Each file As String In FileList
            Dim fInfo As New FileInfo(file)
            Me.ListBox1.Items.Add(fInfo.Name)
            total += 1
            If total >= 2 Then Exit For
        Next

Open in new window

ok that puts just the name of the file now i'm missing two files that have the same keyword

I have the following files:
01 this is a test.m4a
This is a test.m4a
New Text Documen testy.txt
test Microsoft Office Publisher Document.pub
but it only return the first two why?
i need everyfile that has the word test on it
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You do not like the first post?
i do but you did not included the result on the listbox while ipaulino did. thats all not hard feelings!!!!
interested on more points?
https://www.experts-exchange.com/questions/23613979/how-to-create-a-checkbox-dinamically.html
Fernando you started thison the previous question i have =)