Possible Duplicate:
Ignore folders/files when Directory.GetFiles() is denied access
I have this example which loop on files in a specific folder.
Imports system.IO
Dim Files() as string = Directory.GetFiles("D:\example","*.*",SearchOption.AllDirectories)
For Each S As String in Files
Listbox1.Items.Add(S)
Next
Till that point everything is alright. BUT THE PROBLEM GOES HERE: If the user select a top folder (Like a drive "D:\") The code will be as following:
Imports system.IO
Dim Files() as string = Directory.GetFiles("D:\","*.*",SearchOption.AllDirectories)
For Each S As String in Files
Listbox1.Items.Add(S)
Next
The proplem will be an exception [UnauthorizedAccessException] because the loop reached the secured folder 'System volume information', and the program will stop. I need to skip this exception and make the code loop on every file except the protected files and folders like System volume information.
Sorry for inconvenience....