VB.Net program to get the size of a specified folder including a sub-folder

VB.Net program to get the size of a specified folder including a sub-folder I hope we can formalize this useful article. You can also see how the purchase is used.

VB.Net program to get the size of a specified folder including a sub-folder

VB.Net program to get the size of a specified folder including a sub-folder

'Vb.Net program to demonstrate memory stream class.

Imports System.IO
Imports System.Linq

Module Module1
    Function GetSize(ByVal dInfo As DirectoryInfo, ByVal isSubFolder As Boolean) As Long
        Dim sizeInBytes As Long = 0

        sizeInBytes = dInfo.EnumerateFiles().Sum(Function(fi) fi.Length)

        If isSubFolder = True Then
            sizeInBytes += dInfo.EnumerateDirectories().Sum(Function(Dir) GetSize(Dir, True))
        End If
        Return sizeInBytes
    End Function
    
    Sub Main()
        Dim sizeOfDir As Long
        Dim sizeGb As Double

        Dim dInfo As New DirectoryInfo("C:/Intel")
        sizeOfDir = GetSize(dInfo, True)
        sizeGb = (sizeOfDir) / (1024 * 1024 * 1024)

        Console.WriteLine("Size of folder including sub-folder in GB: " & sizeGb)
    End Sub
End Module
Size of folder including sub-folder in GB: 18.12728
Press any key to continue . . .

Final Words

We hope you find the VB.Net program to get the size of a specified folder including a sub-folder article very useful. If this article was helpful to you, we ask that you help your friends benefit too.

Hi, I'm Selva a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Deekshi. Here, I post about programming to help developers.

Share on:

Leave a Comment