MsgBox("Showing Directory size of " & FolderBrowserDialog1.SelectedPath _ If (FolderBrowserDialog1.ShowDialog() = DialogResult.OK) Thenĭim dInfo As New IO.DirectoryInfo(FolderBrowserDialog1.SelectedPath)ĭim sizeOfDir As Long = DirectorySize(dInfo, True) Private Sub form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load You're going to need a FolderBrowserDialog in the form for this to work. It will display the size of the selected in a message box. Interlocked.Add(subTotal, GetFolderSize(subDirs(index), True)) If (File.GetAttributes(subDirs(index)) And FileAttributes.ReparsePoint) FileAttributes.ReparsePoint Then Public Function GetFolderSize(ByVal path As String, Optional recurse As Boolean = True) As Longĭim files() As String = Directory.GetFiles(path)ĭim subDirs() As String = Directory.GetDirectories(path) I just had to put code within Try so it doesn't stop for folders it doesn't have access to, if you also could have such problem just use this (doesn't handle the error just skip it, you can add if important for you): Imports System.IO I use it for my own Backup program which in default setting just backup the whole profile folder, it's a code which finally also is able to understand junction points and read more or less correct size. Please suggest better and faster ways to calculate the size of the directory.īig thanks for Code and for translating to VB.net. However, if I check the size from windows it takes less than a minute. The above methods took around 1 hr 30 mins to calculate the size of the directory. e.g i have a directory with 150,000 sub-folders. ![]() However they take lot of time to calculate the directory size if there are lot of sub-folders. ![]() Select New System.IO.FileInfo(strFile).Length).Sum()īoth these methods work fine. NET? Dim size As Int64 = (From strFile In My.(strFolder, _į) _ Method 2: from What's the best way to calculate the size of a directory in. Public Shared Sub Main(ByVal args() As String)Ĭonsole.WriteLine("You must provide a directory argument at the command line.")Ĭonsole.WriteLine("The size of bytes.", d, dsize) Public Shared Function DirSize(ByVal d As DirectoryInfo) As Longĭim dis As DirectoryInfo() = d.GetDirectories() ' and its subdirectories, if any, and displays the total size ' The following example calculates the size of a directory ![]() I need to calculate the directory size in VB.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |