-1

I am trying to get a list of paths for the last sub directory.

let us assume that I have on my C drive on directory called "Test" as you can see on the Image enter image description here

and I need to get a list of all the last sub Directories only which is marked with red color the results should looked like : C:\test\1\a C:\test\1\b C:\test\1\c C:\test\1\d C:\test\2\a . . . . C:\test\5\d

that is it.

thanks and best regards

HAJJAJ
  • 3,667
  • 14
  • 42
  • 70
  • Have you tried anything? – Bernd Linde May 27 '15 at 06:27
  • yes I had tried , and I got all list directories, what I need only last level sub directories path only not all. – HAJJAJ May 27 '15 at 07:26
  • I had these useful answers : http://stackoverflow.com/questions/12332451/list-all-files-and-directories-in-a-directory-subdirectories http://stackoverflow.com/questions/2407986/get-all-sub-directories-from-a-given-path but it is not exactly what I need. – HAJJAJ May 27 '15 at 07:28
  • Show us what you have tried. Additionally, one could also say the second link provides you with an answer, you just need to read into what the answers code is doing – Bernd Linde May 27 '15 at 07:31

1 Answers1

0

With the help of System.Io You can do this operation. please consider the following code:

    Dim di As DirectoryInfo = New DirectoryInfo("D:\folder")
    Dim directories() As DirectoryInfo = di.GetDirectories("*", SearchOption.AllDirectories)
    Dim ListOfEmptyDirectory As New List(Of String)
    For Each dir As DirectoryInfo In directories
        If dir.GetDirectories("*", SearchOption.AllDirectories).Count = 0 Then
            ListOfEmptyDirectory.Add(dir.FullName)'Gives the List of Last sub directories in the given folder;
        End If
    Next

If you want the List of Last sub directories which is empty then change the condition as follows

   If dir.GetDirectories("*", SearchOption.AllDirectories).Count = 0 And dir.GetFiles().Count() = 0 Then
      ListOfEmptyDirectory.Add(dir.FullName)
   End If