chopperfield chopperfield - 1 year ago 116
Vb.net Question

include or exclude specific folder from Directory.GetDirectories()

how do i include or exclude specific folder from

Directory.GetDirectories()
function

e.g. i have 4 folder at
c:\test1



  1. aa

  2. ab

  3. ac

  4. ad



how do i include only folder
aa
and
ac
from getting
Directory.GetDirectories()
or exclude
ab
and
ad


rootfolder = "c:\test1"
Dim root As String() = Directory.GetDirectories(rootfolder)

Answer Source

You can try checking the names of array elements.simply like

        Dim rootfolder As String
        rootfolder = "c:\test1"
        Dim root As String() = Directory.GetDirectories(rootfolder)
        Dim rootlist As New List(Of String)
        For Each c In root
            If  Path.GetFileName(c) = "aa" Or  Path.GetFileName(c) = "ac" Then  '''' c<>"ab" or c<>"ad"
                rootlist.Add(c)
            End If
        Next
        Dim root1 As String() = rootlist.ToArray()

Glad if it helps you.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download