Get Nested Folder Depth?

  • Thread starter Thread starter Michael Ramey
  • Start date Start date
M

Michael Ramey

Hi,

Is there any easy way to get the number of nested folders for a given path.
for instance I have the following

(trying my best to simulate a view you would see in windows explorer)
c:\temp
\folder1a
\folder1b
\folder2a
\folder1c
\folder2a
\folder3a
\folder2b

If I gave this "function" an input of "c:\temp" it would return 3, since the
most nested folder is 3 levels beneath it (\folder3a). Anyway to do this?

Thanks,
--Michael
 
Just made this, seems to work. Does it recursively

Private Function getDirectoryDepth(ByVal currentPath As String, ByVal
depth As Integer) As Integer
Dim folders() As String = Directory.GetDirectories(currentPath)
Dim curFolder As String
Dim thisDepth As Integer, maxDepth As Integer

maxDepth = depth

For Each curFolder In folders
thisDepth = getDirectoryDepth(curFolder, depth + 1)

If thisDepth > maxDepth Then
maxDepth = thisDepth
End If
Next

Return maxDepth

End Function
 
Back
Top