PDA

Click to See Complete Forum and Search --> : Search for file containing a word? [Resolved]


ProgrammerJon
Feb 12th, 2003, 10:08 AM
I have this code:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' make a reference to a directory
Dim di As New IO.DirectoryInfo("c:\")
Dim diar1 As IO.FileInfo() = di.GetFiles("test.txt")
Dim dra As IO.FileInfo

'list the names of all files in the specified directory
For Each dra In diar1
ListBox1.Items.Add(dra)
Next
End Sub


If I want to filter the search then I change di.GetFiles("righ here")
What do I do if I want to search for something similar to something.

ex.
If I wanted to search for files containg the word "Test" then what would I do?

PT Exorcist
Feb 12th, 2003, 11:43 AM
open each file and do a search for the word "test" using .IndexOf() function

ProgrammerJon
Feb 12th, 2003, 11:56 AM
I don't know how to use the .IndexOF() function.

I'm not sure if you understood the question;
If there were these files in the root of drive c:/
test1.txt
test is my name.txt
test234.txt
my test1.txt
this is test34.txt

Then if I searched for the word "test" then I would want all these to come up. I don't want to search inside a file, I want to search in a directory.

ProgrammerJon
Feb 15th, 2003, 10:57 AM
For the benifit of others this topic has been resolved at this site:
http://www.developerfusion.com/forums/topic.aspx?id=12307

JesusFreak
Mar 2nd, 2003, 06:58 PM
The Easiest way to search for anything is to use the office.FileSearch namespace.

Dim Search As System.Office.FileSearch