Private Sub Command1_Click()
Dim tot As Long
tot = GetDirTotalByte("c:\Program Files\")
Debug.Print tot
End SubPrivate 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
Dim tot As Long
tot = GetDirTotalByte("c:\Program Files\")
Debug.Print tot
End SubPrivate 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
解决方案 »
- 第三天(二)猫姐7777L接分
- 奉献出我作后的60分求 不理解的::一个时间段问题?DateADD()所获得时间,如何与表中的字段(时间)做比较,进来都有分
- 先打开VB环境能运行采集,直接打开工程就不能采集
- 为何我的VB6连ORACLE 9i的数据库编写的程序,查询速度巨慢呢?
- >>>>>>>>>>>>>>>>>>>>>>>>厦门VB程序员大集合<<<<<<<<<<<<<<<<<<<<<<<<<
- ##############请问,如何实现两个TreeView控件中Node节点的互相拖拽?
- 跟踪问题
- 一个高分的问题,高手进来,希望版主帮我。急急急
- 一SQL句子的写法。。
- 我们软件工程要做一个排刻的作业,问几个很菜的数据库问题(白拿高分,我的可用分很多的)
- 关于INET的问题,急急急!!!
- 如何从win2000下读取网上邻居列表?
'功能说明:得到目录(folderspec)下的所有文件大小总和
dim fs, fc
Dim f As Folder
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(folderspec)
'计算文件总和
FilesSize = 0
Set tempFiles = f.Files
Dim tempFile As File
For Each tempFile In tempFiles
FilesSize = FilesSize + tempFile.Size
Next
MsgBox FilesSize / 1024 & "k"
Exit Sub
Public Sub CalculateSizeBelongToFolder(folderspec) '功能说明:得到目录(folderspec)下的所有文件大小总和
dim fs, fc
Dim f As Folder
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(folderspec)
'计算文件总和
FilesSize = 0
Set tempFiles = f.Files
Dim tempFile As File
For Each tempFile In tempFiles
FilesSize = FilesSize + tempFile.Size
Next
MsgBox FilesSize / 1024 & "k"
Exit Sub