Function GetFolderSize(ByVal DirPath As String, _ Optional ByVal IncludeSubFolders As Boolean = True) As Long Dim lngDirSize As Long Dim objFileInfo As FileInfo Dim objDir As DirectoryInfo = New DirectoryInfo(DirPath) Dim objSubFolder As DirectoryInfo Try 'add length of each file For Each objFileInfo In objDir.GetFiles() lngDirSize += objFileInfo.Length Next 'call recursively to get sub folders 'if you don't want this set optional 'parameter to false If IncludeSubFolders Then For Each objSubFolder In objDir.GetDirectories() lngDirSize += GetFolderSize(objSubFolder.FullName) Next End If Catch Ex As Exception End Try Return lngDirSize End Function
Last Updated on October 26, 2015