How to write a program to search the computer for files.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Greetings unto thee.

I want to know how to write an application in vb.net that will search my
computer for files.

An example: Windows Media Player has an option to search your pc for media
files and import them to its media library.

I want to know how to do that (the searching part, not the importing)

Your assistance in this regrard will be utmost appreciated.
 
It's simply a recursive procedure, starting at the root and recursing
through sub-directories - you can maintain a collection of "found" items as
you go....:

Public Sub Scan (ByVal theFoundItems as ArrayList, ByVal theRoot as String)

Scan_Aux ( theFoundItems, theRoot )

End Sub

Public Sub Scan_Aux ( ByVal theFoundItems As ArrayList, ByVal theRoot As
String)

' First recurse through to the leaves....

Dim theDirectories() As String = Directory.GetDirectories ( theRoot )

For Each theDirectory As String In theDirectories
Scan_Aux ( theFoundItems, theDirectory )
Next



' Now scan the files in the current directory for any that match...

Dim theFiles() As String = Directory.GetFiles ( theRoot )

For Each theFile As String In theFiles

If ....<the file matches our criteria> Then
theFoundItems.Add theFile
End If

Next

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top