How do you determine DIRECTORY size?

My question is this:  How can I determine the size of a Directory?  Is there a simple function similar to Filelen(filepath)?  I don't want to scroll through all the files of a directory and add up all the filesizes.

Thanks!
ksmAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
tuviConnect With a Mentor Commented:
Sorry, there is no such function. Even the Windows API don't have it. You have to do the FileSearch which returns the total number of files then do the loop and add the size up. It's not much code at all.
0
 
ksmAuthor Commented:
Can you give me an example of the filesearch routine?
0
 
tuviCommented:
Dim fCount As Long
Dim lngSize As Long

lngSize = 0
With Application.FileSearch
  .FileName = "*.*"
  .LookIn = "C:\" ' or whatever directory
  .SearchSubFolders = True including sub-folders
  If .Execute > 0 Then
    For fCount = 1 To .FoundFiles.Count  
      lngSize = lngSize + FileLen(.FoundFiles(fCount))
    Next fCount
  End If
End With

' lngSize is the size of your directory in bytes
0
 
ksmAuthor Commented:
Excellent.  Thanks.
0
All Courses

From novice to tech pro — start learning today.