- function HumanSize(size)
- Dim Units, Gates, SizeStr
- Units = Array("Byte", "KB", "MB", "GB", "TB")
- Gates = Array(1, 1024, 1024^2, 1024^3, 1024^4)
-
- SizeStr = "0Byte"
- for i=UBound(Units) to 0 Step -1
- if size>=Gates(i) then
- SizeStr = FormatNumber(Size/Gates(i), 2) & Units(i)
- exit for
- end if
- next
- HumanSize = SizeStr
- end function
-
- 'example
- set fso = CreateObject("Scripting.FileSystemObject")
- Size = fso.GetFolder(".").Size
- WScript.Echo Size & " = " & HumanSize(Size)
复制代码
|