Counting the no. of Subdirectories

aroravicky

New member
Joined
Jun 23, 2004
Messages
2
Programming Experience
1-3
I need to count the no. of subdirectories in a directory. Can anybody suggest me how to do that.

Thanks in advance.

Regards,
Vikas
 
Hi try this
Imports System.IO

Dim di As New DirectoryInfo("c:\")

Dim diArr As DirectoryInfo() = di.GetDirectories()

Dim dri As DirectoryInfo

Dim i As Integer

For Each dri In diArr

i += 1

Next dri

MessageBox.Show(i)

 
You may be able to name that tune in a few less notes:

dirArr.Length()
 
If System.IO.Directory.Exists("C:\MyDir") Then

MsgBox(System.IO.Directory.GetDirectories("C:\MyDir").Length())

End If

this is a slightly better way to do it as it checks the directory exists first
 
Back
Top