Hi,
How does one determine the number of files in a directory and the size (MB) of that directory?
Thanks,
Rob
Printable View
Hi,
How does one determine the number of files in a directory and the size (MB) of that directory?
Thanks,
Rob
I'd loop through all files using the Dir function and sum the file size by means of the FileLen function.
e.g.
private Sub Command1_Click()
Dim iCount as Integer
Dim lSize as Long
iCount = GetDirCount("c:\winnt", lSize)
MsgBox iCount & " files; " & lSize & " BYtes"
End Sub
Function GetDirCount(byval strPath as string, byref lSize as Long) as Integer
lSize = 0
Dim iCount as Integer
Dim strFile as string
If Right(strPath, 1) <> "\" then strPath = strPath & "\"
strFile = Dir(strPath & "*.*")
Do While strFile <> ""
iCount = iCount + 1
strFile = strPath & strFile
lSize = lSize + FileLen(strFile)
strFile = Dir
Loop
GetDirCount = iCount
End Function
How can you use that to find out the total size of a directory? Not just files in the immediate directory.
I don't know why nobody has answered this yet, so here it is:
private Function GetFolderSize(folderpath) as Double
Dim fs, f, s
set fs = CreateObject("Scripting.FileSystemObject")
set f = fs.GetFolder(folderpath)
on error resume next
GetFolderSize = f.Size
End Function
It's not that hard, is it? I hope that's what you wanted.
"I'm not biased, I'm Christian."
THANKS!!! That's exactly what I wanted! Not this crap about listing files. It seems like you are the only one who can understand English. Thanks again!