When you provide a link to a file for the user to download, it's sometimes nice to provide the size of the file so that they know what they're getting themselves into.
set fs = Server.CreateObject("Scripting.FileSystemObject")
set file = fs.GetFile(Server.MapPath(someFile))
getFileSize = FormatFileSize(file.size)
set file = nothing
set fs = nothing
size property returns the size in bytes, which could be a very large number. As you may have guessed, we're going to write a FormatFileSize function to wrap around it.
units = Array("B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB")
factor = log(size) \ 7
FormatFileSize = Round(size / (1024 ^ factor), 2) & units(factor)
I think it will be a very, very long time before we reach yottabytes, so this function should withstand the test of time. Next week I'll show you how to get the file type and why you might want that.