I need a bit of help counting folders and subfolders while my program iterates through the filesystem.
I have seen many examples of how to count files inside of folders but I only wish to add +1 to a count for each new directory the iterator travels through.
I hope my question is clear enough and that someone can help me
Ok this is the code I am using thus far but it returns all directory and sub directory counts all at once and not one by one.
Public Function CountDirectories(ByVal dir As DirectoryInfo) As Integer
Try
Dim MySubdirs() As DirectoryInfo = dir.GetDirectories()
Dim count As Integer = MySubdirs.Length
For Each subDir As DirectoryInfo In MySubdirs
count += CountDirectories(subDir)
Next subDir
Return count
Catch ex As Exception
End Try
End Function
Then I am able to show that count to a label by using:
Dim MyDirectoryInfo As New DirectoryInfo(pathToSearchCombo.Text)
Dim Mytotalcount As Integer = CountDirectories(MyDirectoryInfo)
Label12.Text = Mytotalcount
I am looking for a method that will return a folder count one by one while my program iterates the filesystem.
thank you and sorry if this is simple I just cannot think of how??
thank you
cheers!