代码如下:
// 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
这段代码定义了两个函数,用于获取文件的大小并将其格式化为最合适的单位(如B,KB,MB等)。它使用Scripting.FileSystemObject来访问文件系统,并基于CreativeCommonsAttributionLicense发布。
6691

被折叠的 条评论
为什么被折叠?



