首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

如何获取某个目录所占空间的大小

2012-01-28 
怎么获取某个目录所占空间的大小?VB怎么获取某个目录(含子目录)所占空间的大小?不想挨个加文件的大小啊[解

怎么获取某个目录所占空间的大小?
VB怎么获取某个目录(含子目录)所占空间的大小?  
不想挨个加文件的大小啊

[解决办法]
用Api计算。

在外面dim 一个Double Totalsize
dim TotalSize as Double

Private Sub GetFolderSize(ByVal PathName As String)
On Error Resume Next

Dim SearchName As String
Dim Find_Data As WIN32_FIND_DATA
Dim lhandle As Long, ret As Long

Dim Filehandle As Long
Dim i As Long

SearchName = PathName & "\*.* "
lhandle = FindFirstFile(SearchName, Find_Data)
ret = lhandle

Do While ((ret <> 0) And Running)
' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '
'handle the file here
' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '
If (Find_Data.lFileAttributes And FILE_ATTRIBUTE_DIRECTORY) <> 0 Then

If (Left(Find_Data.cFileName, 1) <> ". ") Then 'is a directory
'Debug.Print Pathname & "\ " & TrimZeroSuffix(Find_Data.cFileName) & "\ "
Call Addfiles(PathName & "\ " & TrimZeroSuffix(Find_Data.cFileName), ID)
End If

Else
'is a file
'handle the file here
TotalSize =TotalSize + ConvertSize(Find_Data.nFileSizeHigh, Find_Data.nFileSizeLow)

'Debug.Print Pathname & "\ " & TrimZeroSuffix(Find_Data.cFileName)
End If
DoEvents
ret = FindNextFile(lhandle, Find_Data)
CountX = CountX + 1

Loop

FindClose (lhandle)
End Sub
[解决办法]
引用Microsoft Scripting RunTime

Private fsoTest As New FileSystemObject
Private folder1 As Folder
-----------------------
Set folder1 = fsoTest.GetFolder( "d:\ ")
debug.print folder1.Size/1024/1024
[解决办法]
啊扑

热点排行