Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
Get Folder Size
Author:
Michel Renaud
E-mail:
Click to e-mail author
Submitted:
8/25/2007
Version:
VB 2005
Compatibility:
VB 2005, VB 2008
Category:
Forms
Views:
32919
Function to Calculate folder size.
Declarations:
Imports Microsoft Imports Microsoft.Win32 Imports Microsoft.Win32.Registry Imports System.Collections Imports System.Windows.Forms Imports System.IO Imports System.Threading
Code:
' Returns the sum of the files in the folder. ' dPath: Path of the directory ' include subfolders: set if include subfolders ;) Public abort As Boolean Function GetFolderSize(ByVal DirPath As String, ByVal includeSubFolders As Boolean) As Long Try Dim size As Long = 0 Dim diBase As New DirectoryInfo(DirPath) Dim files() As FileInfo If includeSubFolders Then files = diBase.GetFiles("*", SearchOption.AllDirectories) Else files = diBase.GetFiles("*", SearchOption.TopDirectoryOnly) End If Dim ie As IEnumerator = files.GetEnumerator While ie.MoveNext And Not abort size += DirectCast(ie.Current, FileInfo).Length End While Return size Catch ex As Exception MsgBox("Error: " & ex.Message) Return -1 End Try End Function
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement