http://social.msdn.microsoft.com/for...-5f1be2c0ee4f/
Code from link above which works but has minor issues which I fixed.
Code:
Private Overloads Function DirectorySize(ByVal sPath As String, ByVal bRecursive As Boolean) As Long
Dim lngNumberOfDirectories As Long = 0
Dim Size As Long = 0
Try
Dim fil As FileInfo
Dim diDir As New DirectoryInfo(sPath)
For Each fil In diDir.GetFiles()
Size += fil.Length
Next fil
If bRecursive = True Then
Dim diSubDir As DirectoryInfo
For Each diSubDir In diDir.GetDirectories()
Size += DirectorySize(diSubDir.FullName, True)
lngNumberOfDirectories += 1
Next
End If
Return Size
Catch fex As System.IO.FileNotFoundException
' File not found. Take no action
Catch ex As Exception
' Another error occurred
Return 0
End Try
End Function
Code:
Console.WriteLine(DirectorySize("C:\FolderToCheckSizeOf", True))