找回密码
 加入我们

QQ登录

只需一步,快速开始

搜索
查看: 4376|回复: 0

[磁盘文件] 取得某个目录下所有文件大小的总和

[复制链接]

1214

主题

352

回帖

11

精华

管理员

菜鸟

积分
93755

贡献奖关注奖人气王精英奖乐于助人勋章

发表于 2010-8-8 15:12:20 | 显示全部楼层 |阅读模式
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
【VB】QQ群:1422505加的请打上VB好友
【易语言】QQ群:9531809  或 177048
【FOXPRO】QQ群:6580324  或 33659603
【C/C++/VC】QQ群:3777552
【NiceBasic】QQ群:3703755
您需要登录后才可以回帖 登录 | 加入我们

本版积分规则

快速回复 返回顶部 返回列表