Directory size? 
Author Message
 Directory size?


Quote:
> Can anyone tell me if there is an easy way to calculate the size of a
> directory including all of it's subdirectories and files?
> I have vb5 and have loked at the DIR command but to do it this way seems
> like a lot of code and endless loops?

It's actually not that complicated to just use Dir(), here's a simple
function that should do what you're after:

Public Function CalcSize(ByVal sDir As String) As Long

    If Right(sDir, 1) <> "\" Then
        sDir = sDir & "\"
    End If

    Dim sFile As String
    Dim colDirs As Collection
    Set colDirs = New Collection

    sFile = Dir(sDir, vbDirectory + vbHidden + vbSystem)
    Do Until sFile = ""
        If sFile <> "." And sFile <> ".." Then
            If GetAttr(sDir & sFile) And vbDirectory Then
                colDirs.Add sDir & sFile & "\"
            Else
                CalcSize = CalcSize + FileLen(sDir & sFile)
            End If
        End If

        Debug.Print sFile

        sFile = Dir()
    Loop

    While colDirs.Count > 0
        CalcSize = CalcSize + CalcSize(colDirs.Item(1))
        colDirs.Remove 1
    Wend

    Set colDirs = Nothing
End Function

--

http://www.*-*-*.com/
Sample code, message forum, and utilities..



Sat, 27 Apr 2002 03:00:00 GMT  
 Directory size?
Can anyone tell me if there is an easy way to calculate the size of a
directory including all of it's subdirectories and files?
I have vb5 and have loked at the DIR command but to do it this way seems
like a lot of code and endless loops?

can anyone help

brendon



Sun, 28 Apr 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Find file and directory size...

2. FileSystemWatcher Path / Directory size

3. How do you get directory size in vb.net

4. getting directory size

5. Please tell me how to find a directory size

6. Directory size in bytes

7. getting directory size in vb

8. Directory size?

9. counting directory size

10. How do you determine DIRECTORY size?

11. Directory sizes

12. Directory Size?

 

 
Powered by phpBB® Forum Software