|
|
Title | Get a directory's size (not including subdirectories) |
Keywords | DirSize, directory size |
Categories | Files 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.
|
|
|
|
|
|