Returns directory names that match a search pattern in a specified path, and optionally searches subdirectories.
Imports System.Collections.Generic
Imports System.IO
Imports System.Linq
Module Module1
Sub Main()
Try
Dim dirPath As String = "\\archives\2009\reports"
Dim dirs = From folder In Directory.EnumerateDirectories(dirPath, "a_*",SearchOption.AllDirectories)
For Each folder In dirs
Console.WriteLine("{0}",folder.Substring(folder.LastIndexOf("\") + 1))
Next
Console.WriteLine("{0} directories found.",dirs.Count.ToString())
Dim workDirs As List(Of String) = New List(Of String)
Catch PathEx As Exception
Console.WriteLine(PathEx.Message)
End Try
End Sub
End Module
Related examples in the same category