How can I error handle ;
when FLDR returns access deniedCode:For each FLDR As String In my.computer.filesystem.getdirectories("C:\","*")
~ PROCESS FLDR ~
Next
THANKS!
Printable View
How can I error handle ;
when FLDR returns access deniedCode:For each FLDR As String In my.computer.filesystem.getdirectories("C:\","*")
~ PROCESS FLDR ~
Next
THANKS!
May you should try searching specific folders instead of the entire c drive which can have access restriction on certain folders (System folder for example)Code:For Each FLDR As String In My.Computer.FileSystem.GetDirectories("D:\Setup", FileIO.SearchOption.SearchAllSubDirectories, "*")
MessageBox.Show(FLDR)
Next
There is no way to handle that exception and complete the search. I think that is a big oversight with that method but you can only work with what you've got. If your folder tree may contain inaccessible folders then you have no choice but to perform your own recursive search. That way you can simply ignore an access denied exception and move on to the next folder:vb Code:
Public Function GetDirectories(ByVal path As String) As List(Of String) Dim subfolders As New List(Of String) For Each subfolder As String In IO.Directory.GetDirectories(path) subfolders.Add(subfolder) Try subfolders.AddRange(GetDirectories(subfolder)) Catch ex As UnauthorizedAccessException 'Ignore this folder and move on. End Try Next subfolder Return subfolders End Function