title: Recursive File Search in VB.NET
body: <p>I have a function that does a recursive directory search for files but when I search a Drive I get Access denied errors which stops the search. How can I avoid these errors?</p>
  
  <p>Here's the function I use:</p>
  
  <pre><code>lstSearch = GetFilesRecursive(FolderBrowserDialogMain.SelectedPath)
  
  Private Function GetFilesRecursive(ByVal path As String) As List(Of String)
      Dim lstResult As New List(Of String)
      Dim stkStack As New Stack(Of String)
      stkStack.Push(path)
      Do While (stkStack.Count &gt; 0)
          Dim strDirectory As String = stkStack.Pop
          Try
              lstResult.AddRange(Directory.GetFiles(strDirectory, "*.mp3"))
              Dim strDirectoryName As String
              For Each strDirectoryName In Directory.GetDirectories(strDirectory)
                  stkStack.Push(strDirectoryName)
              Next
          Catch ex As Exception
          End Try
      Loop
      Return lstResult
  End Function
  </code></pre>
  
  <p>Thanks for any solutions.</p>