DirectoryInfo.EnumerateDirectories Method (String, SearchOption)
Imports System
Imports System.IO
Class Program
Public Shared Sub Main(ByVal args As String())
Dim diTop As New DirectoryInfo("d:\")
Try
For Each fi In diTop.EnumerateFiles()
Try
Console.WriteLine("{0}" & vbTab & vbTab & "{1}", fi.FullName, fi.Length.ToString("N0"))
Catch UnAuthTop As UnauthorizedAccessException
Console.WriteLine("{0}", UnAuthTop.Message)
End Try
Next
For Each di In diTop.EnumerateDirectories("*")
Try
For Each fi In di.EnumerateFiles("*", SearchOption.AllDirectories)
Console.WriteLine("{0}" & vbTab &vbTab & "{1}", fi.FullName, fi.Length.ToString("N0"))
Next
Catch UnAuthSubDir As UnauthorizedAccessException
Console.WriteLine("UnAuthSubDir: {0}", UnAuthSubDir.Message)
End Try
Next
Catch LongPath As Exception
Console.WriteLine("{0}", LongPath.Message)
End Try
End Sub
End Class
Related examples in the same category