首页 > 学院 > 开发设计 > 正文

取得某个目录底下所有文件大小总和

2019-11-18 17:34:51
字体:
来源:转载
供稿:网友
含目录底下的子目录,求得其所有文件大小之总和其第二个叁数的目的是起始Static型态的totbyte,呼叫它时,请不要传叁数进去
PRivateSubCommand1_Click()
DimtotAsLong
tot=GetDirTotalByte("c:/tools/")
Debug.Printtot
EndSub
PrivateFunctionGetDirTotalByte(CurrentPathAsString,OptionaliAsLong)AsLong
StatictotbyteAsLong
DimnIAsInteger,nDirectoryAsInteger
DimsFileNameAsString,sDirectoryList()AsString
注释:Initialtotbyte,ifitisnottheRecursivecallthefunction
Ifi<>1Then
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->


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