1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| Public Function DirSize(path As String)
Dim fp As FILE_PARAMS
With fp
.sFileRoot = QualifyPath(path) 'start path
.sFileNameExt = "*.*" 'files of interest
.bRecurse = True 'True = recurse
End With
Call GetDirectorySize(fp.sFileRoot, fp)
DirSize = fp.nFileSize 'utiliser nSearched : le nombre...
End Function
Private Function QualifyPath(sPath As String) As String
If Right$(sPath, 1) <> "\" Then
QualifyPath = sPath & "\"
Else
QualifyPath = sPath
End If
End Function
Private Sub GetDirectorySize(sRoot As String, fp As FILE_PARAMS)
Dim wfd As WIN32_FIND_DATA
Dim hFile As Long
hFile = FindFirstFile(sRoot & "*.*", wfd)
If hFile <> INVALID_HANDLE_VALUE Then
Do
If Asc(wfd.cFileName) <> vbDot Then
If (wfd.dwFileAttributes And vbDirectory) Then
If fp.bRecurse Then
GetDirectorySize sRoot & TrimNull(wfd.cFileName) & "\", fp
End If 'If fp.bRecurse
Else
fp.nFileCount = fp.nFileCount + 1
fp.nFileSize = fp.nFileSize + _
((wfd.nFileSizeHigh * _
(MAXDWORD + 1)) + _
wfd.nFileSizeLow)
End If 'If WFD.dwFileAttributes
End If 'If Asc(wfd.cFileName)
fp.nSearched = fp.nSearched + 1
Loop While FindNextFile(hFile, wfd)
End If 'If hFile
Call FindClose(hFile)
End Sub
Private Function TrimNull(startstr As String) As String
TrimNull = Left$(startstr, lstrlen(StrPtr(startstr)))
End Function |
Partager