Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
 
 
 
500MB 27GB Web Hosting - $9.95/Month
 
 
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
TitleGet a directory's size (not including subdirectories)
KeywordsDirSize, directory size
CategoriesFiles & 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-2003 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated