Use this recursive method. It allows you to trap the exception and continue.
I put together another version that tested the access rights first but took 60% longer than just catching the exeception.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim path As String = "C:\"
Dim TotalFiles As Integer = GetDirectoryFileCount(path)
End Sub
Private Function GetDirectoryFileCount(ByVal directoryPath As String) As Integer
Dim TotalFiles As Integer
Try
TotalFiles += System.IO.Directory.GetFiles(directoryPath).Count
For Each Directory As String In System.IO.Directory.GetDirectories(directoryPath)
TotalFiles += GetDirectoryFileCount(Directory)
Next
Catch ex As Exception
End Try
Return TotalFiles
End Function