Vb.Net: Recursive File Count
Function CountFiles(ByVal Directory As String) As Integer
'Recursive File Counter
'by Derek Anderson
'dim variables
Dim FileCount As Integer = 0
Dim SubDirectory() As String
Dim i As Integer
'get the count of files in the current directory
FileCount = System.IO.Directory.GetFiles(Directory).Length
'get a list of sub directories from current directory
SubDirectory = System.IO.Directory.GetDirectories(Directory)
'for ever sub directory, count the files and add to file count
'this is a recursive routine, so it will call this again and
'return the file count of every directory, and add it to the file
'count originally started
For i = 0 To SubDirectory.Length - 1
FileCount = CountFiles(SubDirectory(i)) + FileCount
Next
Return FileCount
End Function