Question

I'm trying to pull back a list of directories that sit inside a dated folder structure. Within each dated folder could be a number of 'Jobs' however i only want to return the name of the 1st level of folders

The below code gets to the right level of folder detail however the result displays the full path

 For Each Dir As String In System.IO.Directory.GetDirectories("c:\Working")
        Dim dirInfo As New System.IO.DirectoryInfo(Dir)
        For Each sDir As String In System.IO.Directory.GetDirectories(dirInfo.ToString)
            Dim sdirInfo As New System.IO.DirectoryInfo(sDir)
            chkImpExp.Items.Add(sDir)
        Next
    Next

This would display the following

Folder Structure

However i would just like to display the directory name to the right of the 3rd backslash (Westdale - 28023 - Cash+Spirit for example)

Hopefully this is enough information.

Many thanks

Was it helpful?

Solution

' renamed Dir to d as Dir() is already a function in Microsoft.VisualBasic
For Each d In System.IO.Directory.GetDirectories("c:\Working")
    For Each sDir In System.IO.Directory.GetDirectories(d)
        Dim di = New DirectoryInfo(sDir)
        chkImpExp.Items.Add(di.Name())
    Next
Next

OTHER TIPS

Try:

chkImpExp.Items.Add(sdirInfo.Name)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top