Wednesday, April 1, 2009

VB.Net - Get Directory / Folder Size


Public Function GetFolderSize(ByVal path As String, _
ByVal includeSubFolders As Boolean) As Long

GetFolderSize = 0

Dim main_dir As New System.IO.DirectoryInfo(path)
Dim dir_files() As FileInfo

If includeSubFolders Then
dir_files = main_dir.GetFiles("*", SearchOption.AllDirectories)
Else
dir_files = main_dir.GetFiles("*", SearchOption.TopDirectoryOnly)
End If

For Each ofile As IO.FileInfo In dir_files
GetFolderSize = GetFolderSize + ofile.Length
Next

End Function

No comments:

Post a Comment