Skiping the Not accessible directory

Feb 26 2011 9:13 AM
I have written a code for populating the folder structure into tree view. But whenever the folder is not accesible its throwing an error or keeps waiting. I want it to skip that folder and move to next folder. Below is my code

 Private Sub BuildDirectoryTree()
  Dim newDirectory As TreeNode
  Dim justTheSubdirectory As String
 Dim basePath as String = "C:\"
  For Each oneDirectory As String In My.Computer.FileSystem.GetDirectories(basePath)
  justTheSubdirectory = My.Computer.FileSystem.GetName(oneDirectory)
  If (fromNode Is Nothing) Then
  newDirectory = FrmTreeViewDirectory.Nodes.Add(justTheSubdirectory)
  Else
  newDirectory = fromNode.Nodes.Add(justTheSubdirectory)
  End If
  BuildDirectoryTree(newDirectory, My.Computer.FileSystem.CombinePath(basePath, justTheSubdirectory))
  Next oneDirectory
  End Sub

Can any one modify this and post it back so that it works for the folders that its accessible

Answers (9)