我有一个函数用于递归搜索文件目录,但当我搜索驱动器时,会出现访问被拒绝的错误,导致搜索停止。该如何避免这些错误?
以下是我使用的函数:
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 > 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
感谢任何解决方案。
Stack
? - Trevor