This is vb.net extension method to find the total number of files in a folder. There is one exception. It will omit the system restricted file which can not be accessed. Recursively call itself to calculate subdirectories.
Public Function GetTotalFiles(ByVal di As DirectoryInfo) As Int32
Dim total As Int32
total += di.GetFiles().Length
Dim dis As DirectoryInfo() = di.GetDirectories()
For Each d As DirectoryInfo In dis
total += d.GetTotalFiles()
Dim di As New DirectoryInfo("C://MyFolder")
Dim fileCount = di.GetTotalFiles()
Need to import following to use this method
Just a normal software developer who love to write code. Developing professional software since 1999. After working in the software industry for many years, I've started my own website to share knowledges and experiences.