取得某个目录底下所有文件大小总和
想不想get新技能酷炫一下,今天图老师小编就跟大家分享个简单的取得某个目录底下所有文件大小总和教程,一起来看看吧!超容易上手~
PrivateSubCommand1_Click()
DimtotAsLong
tot=GetDirTotalByte("c:ools")
Debug.Printtot
EndSub
PrivateFunctionGetDirTotalByte(CurrentPathAsString,OptionaliAsLong)AsLong
StatictotbyteAsLong
DimnIAsInteger,nDirectoryAsInteger
DimsFileNameAsString,sDirectoryList()AsString
注释:Initialtotbyte,ifitisnottheRecursivecallthefunction
Ifi1Then
totbyte=0
EndIf
注释:Firstlistallnormalfilesinthisdirectory
sFileName=Dir(CurrentPath,vbNormal vbHidden vbReadOnly vbSystem vbArchive)
DoWhilesFileName""
totbyte=totbyte FileLen(CurrentPath sFileName)
sFileName=Dir
Loop
注释:Nextbuildtemporarylistofsubdirectories
sFileName=Dir(CurrentPath,vbDirectory)
DoWhilesFileName""
注释:Ignorecurrentandparentdirectories
IfsFileName"."AndsFileName".."Then
注释:Ignorenondirectories
IfGetAttr(CurrentPath&sFileName)_
AndvbDirectoryThen
nDirectory=nDirectory 1
ReDimPreservesDirectoryList(nDirectory)
sDirectoryList(nDirectory)=CurrentPath&sFileName
EndIf
EndIf
sFileName=Dir
Loop
注释:Recursivelyprocesseachdirectory
FornI=1TonDirectory
GetDirTotalBytesDirectoryList(nI)&"",1
NextnI
GetDirTotalByte=totbyte
EndFunction->