So, I am trying to make a File-Search-Program, which should also search through all sub-folders of the given folder. The problem is, that if I want to search on C:\
for example, I get an UnauthorizedAccessException
. I know that I could make a "Try"-Statement, but that doesn't work either because then the FileInfo stays Nothing.
Here's my code:
Sub SubfolderSearch()
Dim diar2 As IO.FileInfo()
Dim di2 As New IO.DirectoryInfo(Path)
diar2 = di2.GetFiles("*", IO.SearchOption.AllDirectories) 'The Error occurs in this line
Dim dra As IO.FileInfo
For Each dra In diar2
Dim FileName As String = dra.Name
Dim FilePath As String = dra.FullName
Dim FileSize As Integer = dra.Length / 1000
'Search Procedure'
Next
SubfolderThread.Abort()