Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleGet a directory's size (not including subdirectories)
KeywordsDirSize, directory size
CategoriesFiles and Directories
 
Use the Dir$ function to examine all of the files in the directory. Use FileLen to get their lengths.
 
' Return the number of bytes used by this directory.
' This does not include subdirectories.
Private Function DirSize(ByVal dir_name As String) As Double
Dim total_size As Double
Dim file_name As String

    If Right$(dir_name, 1) <> "\" Then dir_name = dir_name _
        & "\"

    file_name = Dir$(dir_name)
    Do While Len(file_name) > 0
        total_size = total_size + FileLen(dir_name & _
            file_name)
        file_name = Dir$()
    Loop

    DirSize = total_size
End Function
 
This example also shows how to format large numbers of bytes (KB, MB, GB, etc.). See also Format a BIG number of bytes in KB, MB, GB, TB, etc.
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated