vb.netdirectoryinfo

Conditional directory info on VB


I'm looking for the folders information with the method : Dim Drs() As IO.DirectoryInfo = di.GetDirectories()

But I want only to save on this array the folders that contain "CP" on the beginning of the name .

How do I work this out?

Best Regards A


Solution

  • You can use LINQ:

    Dim directoryQuery = From dir In di.EnumerateDirectories()
                         Where dir.Name.StartsWith("CP")
    Dim Drs() As IO.DirectoryInfo = directoryQuery.ToArray()