Quote:
>How can I check the size of a directory, including all sub directories??
Here's one I prepared earlier (VB5 SP3). Sample usage:
MsgBox DirSize("C:\") ' this does the root dir only
MsgBox DirSize("C:\WINDOWS\", IncludeSubDirs:=True) ' WINDOWS and all subdirectories
Note this misses hidden files, but it shouldn't be hard to change that if it's a problem
to you. Also it was edited for posting so there might be typos.
'----------------------------------------------------------------------
Private Function DirSize(ByVal DirName As String, Optional ByVal IncludeSubDirs As _
Boolean) As Long
' For correct results, DirName should end in "\"
Dim FileName As Variant, Directories As New Collection, SubDirName as Variant
FileName = Dir(DirName)
While FileName <> ""
DirSize = DirSize + FileLen(DirName & FileName)
FileName = Dir
Wend
If IncludeSubDirs Then
SubDirName = Dir(DirName, vbDirectory)
While SubDirName <> ""
If SubDirName <> "." And SubDirName <> ".." Then Directories.Add SubDirName
SubDirName = Dir
Wend
For Each SubDirName In Directories
DirSize = DirSize + DirSize(DirName & SubDirName & "\", IncludeSubDirs:=True)
Next SubDirName
End If
End Function
'----------------------------------------------------------------------
HTH
--
-- Mike Barnes, Owner, Exodus Computer Systems, Stockport, England.
-- If you post a response to Usenet, please *don't* send me a copy by e-mail.