Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1799369
  • 博文数量: 600
  • 博客积分: 10581
  • 博客等级: 上将
  • 技术积分: 6205
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-06 10:13
文章分类
文章存档

2016年(2)

2015年(9)

2014年(8)

2013年(5)

2012年(8)

2011年(36)

2010年(34)

2009年(451)

2008年(47)

分类:

2009-10-11 10:44:20




含目录底下的子目录,求得其所有文件大小之总和
其第二个叁数的目的是起始Static型态的totbyte, 呼叫它时,请不要传叁数进去


Private Sub Command1_Click()
Dim tot As Long
tot = GetDirTotalByte("c:\tools\")
Debug.Print tot
End Sub
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
阅读(534) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~