代码如下:
// Beginning
' Copyright (c) 2009, reusablecode.blogspot.com; some rights reserved.
' This work is licensed under the Creative Commons Attribution License. To view
' send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California
' Retrieve the file size of a given file.
Function getFileSize(someFile)
Dim fs
Dim file
Set fs = CreateObject("Scripting.FileSystemObject")
Set file = fs.GetFile(someFile)
getFileSize = FormatFileSize(file.size)
Set file = Nothing
Set fs = Nothing
End Function
' Format a file size in the most practical units.
' Input: size in bytes
Function FormatFileSize(size)
Dim units
Dim factor
units = Array("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB")
factor = Log(size) \ 7
FormatFileSize = Round(size / (1024 ^ factor), 2) & units(factor)
End Function
// End