Do While ((ret <> 0) And Running) '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'handle the file here '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' If (Find_Data.lFileAttributes And FILE_ATTRIBUTE_DIRECTORY) <> 0 Then
If (Left(Find_Data.cFileName, 1) <> ".") Then 'is a directory 'Debug.Print Pathname & "\" & TrimZeroSuffix(Find_Data.cFileName) & "\" Call Addfiles(PathName & "\" & TrimZeroSuffix(Find_Data.cFileName), ID) End If
Else 'is a file 'handle the file here TotalSize =TotalSize + ConvertSize(Find_Data.nFileSizeHigh, Find_Data.nFileSizeLow)
'Debug.Print Pathname & "\" & TrimZeroSuffix(Find_Data.cFileName) End If DoEvents ret = FindNextFile(lhandle, Find_Data) CountX = CountX + 1
Loop
FindClose (lhandle) End Sub
引用Microsoft Scripting RunTimePrivate fsoTest As New FileSystemObject Private folder1 As Folder ----------------------- Set folder1 = fsoTest.GetFolder("d:\") debug.print folder1.Size/1024/1024
在外面dim 一个Double Totalsize
dim TotalSize as Double
Private Sub GetFolderSize(ByVal PathName As String)
On Error Resume Next
Dim SearchName As String
Dim Find_Data As WIN32_FIND_DATA
Dim lhandle As Long, ret As Long
Dim Filehandle As Long
Dim i As Long
SearchName = PathName & "\*.*"
lhandle = FindFirstFile(SearchName, Find_Data)
ret = lhandle
Do While ((ret <> 0) And Running)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'handle the file here
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
If (Find_Data.lFileAttributes And FILE_ATTRIBUTE_DIRECTORY) <> 0 Then
If (Left(Find_Data.cFileName, 1) <> ".") Then 'is a directory
'Debug.Print Pathname & "\" & TrimZeroSuffix(Find_Data.cFileName) & "\"
Call Addfiles(PathName & "\" & TrimZeroSuffix(Find_Data.cFileName), ID)
End If
Else
'is a file
'handle the file here
TotalSize =TotalSize + ConvertSize(Find_Data.nFileSizeHigh, Find_Data.nFileSizeLow)
'Debug.Print Pathname & "\" & TrimZeroSuffix(Find_Data.cFileName)
End If
DoEvents
ret = FindNextFile(lhandle, Find_Data)
CountX = CountX + 1
Loop
FindClose (lhandle)
End Sub
Private folder1 As Folder
-----------------------
Set folder1 = fsoTest.GetFolder("d:\")
debug.print folder1.Size/1024/1024