首页 > 编程 > Visual Basic > 正文

计算某个目录所占字节数的函数

2023-06-12 12:11:31
字体:
来源:转载
供稿:网友

下面的函数用来计算某个文件目录所占的字节数:

REM 函数返回值为目录所占字节数
Function DirUsedBytes(ByVal dirName As String) As Long
          Dim FileName As String
          Dim FileSize As Currency
          If Right$(dirName, 1) <> "/" Then
               dirName = dirName & "/"
          Endif
          FileSize = 0
          FileName = Dir$(dirName & "*.*")
          Do While FileName <> ""
                 FileSize = FileSize +  FileLen(dirName & FileName)
                FileName = Dir$
          Loop
          DirUsedBytes = FileSize
end function

使用方法:

MsgBox DirUsedBytes("D:/musics")

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表