下面的函數用來計算某個檔案目錄所佔的位元組數:
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)