Ignore errors when scanning for files in C:\

Posted by Shane on Stack Overflow See other posts from Stack Overflow or by Shane
Published on 2010-06-07T05:09:39Z Indexed on 2010/06/07 5:12 UTC
Read the original article Hit count: 349

Filed under:
|
|
|

I am trying to search the C:\ drive for all files with a certain extension. I am using the following code which is working fine, however when it encounters an error the whole process stops rather than continuing with the scan. (running in backgroundworker, hence the invoke)

Private Sub ScanFiles(ByVal rootFolder As String, ByVal fileExtension As String)

        'Determine if the current folder contains any sub folders
        Dim subFolders() As String = System.IO.Directory.GetDirectories(rootFolder)

        For Each subFolder As String In subFolders
            ScanFiles(subFolder, fileExtension)
        Next
            For Each file As String In System.IO.Directory.GetFiles(rootFolder, fileExtension)
                lb.BeginInvoke(New AddValue(AddressOf AddItems), file)
            Next

    End Sub

How can I make this code continue once an error is encountered? Thanks for your help.

© Stack Overflow or respective owner

Related posts about vb.net

Related posts about listbox