Private Function GetDirTotalByte(CurrentPath As String, Optional i As Long) As Long
Static totbyte As Long
Dim nI As Integer, nDirectory As Integer
Dim sFileName As String, sDirectoryList() As String
' 注释:Initial totbyte, if it is not the Recursive call the function
If i <> 1 Then
totbyte = 0
End If
' 注释:First list all normal files in this directory
sFileName = Dir(CurrentPath, vbNormal + vbHidden + vbReadOnly + vbSystem + vbArchive)
Do While sFileName <> ""
totbyte = totbyte + FileLen(CurrentPath + sFileName)
sFileName = Dir
Loop
' 注释:Next build temporary list of subdirectories
sFileName = Dir(CurrentPath, vbDirectory)
Do While sFileName <> ""
' 注释:Ignore current and parent directories
If sFileName <> "." And sFileName <> ".." Then
'注释: Ignore nondirectories
If GetAttr(CurrentPath & sFileName) _
And vbDirectory Then
nDirectory = nDirectory + 1
ReDim Preserve sDirectoryList(nDirectory)
sDirectoryList(nDirectory) = CurrentPath & sFileName
End If
End If
sFileName = Dir
Loop
' 注释:Recursively process each directory
For nI = 1 To nDirectory
GetDirTotalByte sDirectoryList(nI) & "\", 1
Next nI
GetDirTotalByte = totbyte
End Function
Static totbyte As Long
Dim nI As Integer, nDirectory As Integer
Dim sFileName As String, sDirectoryList() As String
' 注释:Initial totbyte, if it is not the Recursive call the function
If i <> 1 Then
totbyte = 0
End If
' 注释:First list all normal files in this directory
sFileName = Dir(CurrentPath, vbNormal + vbHidden + vbReadOnly + vbSystem + vbArchive)
Do While sFileName <> ""
totbyte = totbyte + FileLen(CurrentPath + sFileName)
sFileName = Dir
Loop
' 注释:Next build temporary list of subdirectories
sFileName = Dir(CurrentPath, vbDirectory)
Do While sFileName <> ""
' 注释:Ignore current and parent directories
If sFileName <> "." And sFileName <> ".." Then
'注释: Ignore nondirectories
If GetAttr(CurrentPath & sFileName) _
And vbDirectory Then
nDirectory = nDirectory + 1
ReDim Preserve sDirectoryList(nDirectory)
sDirectoryList(nDirectory) = CurrentPath & sFileName
End If
End If
sFileName = Dir
Loop
' 注释:Recursively process each directory
For nI = 1 To nDirectory
GetDirTotalByte sDirectoryList(nI) & "\", 1
Next nI
GetDirTotalByte = totbyte
End Function
解决方案 »
- 问两个窗口,怎么让其中一个窗口吸附另一个
- VB6 --> 菜单 --> 引用
- 【LOOK!】本人一年多来上网收集的经典文章,给大家分享(内详...)
- 什么情况下ADO会造成 'FROM 子句语法错误' 小弟在线急求正解!!!!!
- 怎么样用VB在Outlook里面搜索我所想要邮件,并得到其中的附件?
- 谁有显示PNG图像的OCX控件或者DLL文件
- 返回控件的上层容器名称??????//
- 各位大侠帮小弟一下吧这里有分给(100分)!!!!
- 怎样修改文件
- 在VB中哪个函数相当于VFP中的mod()函数
- 小妹求教各位哥哥关于vb报表打印及时刷新的问题?
- 散分了,请问实现一张报表上有两个数据表的内的数据,怎么办? 在线等待?
Dim tot As Long
tot = GetDirTotalByte("f:\help\")
Debug.Print tot
End Sub
得出的是字节,你可以换算成K