I'm using a small project to search for files. What I'm finding is that while this does recursively search, there will be times when I want to target a specific folder inside of the search area. I thought of using a combo box with a list of all the other folders inside the search area but there are 90 of these and at any given time that may increase or decrease depending on who adds or deletes from the search area. For now, let's say the search area is a folder called "C:\MyFolder".
I was thinking that maybe an Explorer type window which could popup and allow the user to click on one of the folders beneath C:\MyFolder to narrow the search area down to a specific folder instead of all of them. This screen shot shows my attempt at using a combo box but due to the fact that the number of folders beneath C:\MyFolder will not remain static, I think there should be a better approach.
Code:
Imports System.IO
Public Class Form1
Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
lstFilesFound.Items.Clear()
txtFile.Enabled = False
btnSearch.Text = "Searching..."
Me.Cursor = Cursors.WaitCursor
Application.DoEvents()
DirSearch("C:\MyFolder\")
btnSearch.Text = "Search"
Me.Cursor = Cursors.Default
txtFile.Enabled = True
End Sub
Sub DirSearch(ByVal sDir As String)
Dim d As String
Dim f As String
Try
For Each d In Directory.GetDirectories(sDir)
For Each f In Directory.GetFiles(d, txtFile.Text)
lstFilesFound.Items.Add(f)
Next
DirSearch(d)
Next
Catch excpt As System.Exception
Debug.WriteLine(excpt.Message)
End Try
End Sub
Private Sub lstFilesFound_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lstFilesFound.SelectedIndexChanged
Process.Start(lstFilesFound.SelectedItem)
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
End Class