tommyt11
Member
Hi, I'm confused. This code works fine as long as directory chosen from directory dialog is not a root directory on any drive. Example if I choose C:/ or F:/ it fails and I get exception:
'System.UnauthorizedAccessException' occurred in mscorlib.dll.
Is there a way to handle this exception and continue the process on folders not readonly or set permissions so I can.
If I choose a subdirectory. example F:/Something it works as I assume there is no permissions problems at the lower level.
Here is code:
Public Sub GetFilesForTransfer()
On Error Resume Next
Dim SelectedsearchPath = SearchPathTextBox.Text
Dim searchMask = MaskComboBoxMain.Text
If SubFoldersYes.Checked Then
For Each foundFile As String In My.Computer.FileSystem.GetFiles(SelectedsearchPath, FileIO.SearchOption.SearchAllSubDirectories, searchMask)
SearchResultsListBox.Items.Add(foundFile)
Next
Else
For Each foundFile As String In My.Computer.FileSystem.GetFiles(SelectedsearchPath, FileIO.SearchOption.SearchTopLevelOnly, searchMask)
SearchResultsListBox.Items.Add(foundFile)
Next
End If
On Error Resume Next
End Sub
'System.UnauthorizedAccessException' occurred in mscorlib.dll.
Is there a way to handle this exception and continue the process on folders not readonly or set permissions so I can.
If I choose a subdirectory. example F:/Something it works as I assume there is no permissions problems at the lower level.
Here is code:
Public Sub GetFilesForTransfer()
On Error Resume Next
Dim SelectedsearchPath = SearchPathTextBox.Text
Dim searchMask = MaskComboBoxMain.Text
If SubFoldersYes.Checked Then
For Each foundFile As String In My.Computer.FileSystem.GetFiles(SelectedsearchPath, FileIO.SearchOption.SearchAllSubDirectories, searchMask)
SearchResultsListBox.Items.Add(foundFile)
Next
Else
For Each foundFile As String In My.Computer.FileSystem.GetFiles(SelectedsearchPath, FileIO.SearchOption.SearchTopLevelOnly, searchMask)
SearchResultsListBox.Items.Add(foundFile)
Next
End If
On Error Resume Next
End Sub