The followinig code works, but I'm looking for something even faster.
Public Function RecursiveSearch(ByRef array As ArrayList, _
ByVal strDir As String, ByVal bwWorker As BackgroundWorker, _
ByVal e As DoWorkEventArgs) As Boolean
Dim dirInfo As New IO.DirectoryInfo(strDir)
' Try to get the files for this directory
Dim pFileInfo() As IO.FileInfo
Try
pFileInfo = dirInfo.GetFiles()
Catch ex As UnauthorizedAccessException
Return False
Exit Function
End Try
' Add the file infos to the array
array.AddRange(pFileInfo)
'report progress, raises progress changed event
bwWorker.ReportProgress(array.Count)
' Try to get the subdirectories of this one
Dim pdirInfo() As IO.DirectoryInfo
Try
pdirInfo = dirInfo.GetDirectories()
Catch ex As UnauthorizedAccessException
Return False
Exit Function
End Try
' Iterate through each directory and recurse
Dim dirIter As IO.DirectoryInfo
For Each dirIter In pdirInfo
If bwWorker.CancellationPending Then
e.Cancel = True
Else
RecursiveSearch(array, dirIter.FullName, bwWorker, e)
End If
Next dirIter
Return True
End Function
"Marina Levit [MVP]" <so*****@nospam.comwrote in message
news:%2***************@TK2MSFTNGP05.phx.gbl...
Put a Try/Catch around that line, then do nothing in the catch. In the
code following the try/catch, make sure you are not relying on GetFiles
succeeding.
"Chris" <co***********@nospam.yahoo.comwrote in message
news:ei**************@TK2MSFTNGP05.phx.gbl...
>Hi everyone,
I'm trying to find the fastest way to get all the files from the local c:
drive. I have even considered the api calls findfirst/findnext, but read
that in VB.net it's best to use the GetFiles function.
I'm using:
Dim files As String() = System.IO.Directory.GetFiles("c:\", "*.*",
IO.SearchOption.AllDirectories)
and get UnAuthorizeException was unhandled: "Access to the path
'c:\System Volume Information' is denied."
Is there any way I can just ignore the exception and have the program
continue where it left off?
Thanks,
Chris