FileSize_Formatted

Returns file size in formated human way (mb, gb, etc..)
Or, it can format any number into filesize format
Or, it can return filesize without formating

Function FileSize_Formatted(FullFilePath, orFileSize, Formatted)
' Gets file size in tb, gb, mb, or kb
' Needs either the full path to file, or the filesize
'
If FullFilePath > "" Then
  set t     = fso.getfile(Server.MapPath(FullFilePath))
siz     = t.size ' 3555 ' FileLen(Server.MapPath(FullFilePath))
Else
siz     = orFileSize
End If
If Formatted = 0 Then
FileSize_Formatted = siz
Exit Function
End If
If siz < 1024 Then
t1      = FormatNumber(siz, 1) & "B"
ElseIf siz < 1024^2 Then
t1      = FormatNumber(siz / 1024, 1) & "KB" '   Kilobyte
ElseIf siz < 1024^3 Then
t1      = FormatNumber(siz / 1024^2, 1) & "MB" '  Megabyte
ElseIf siz < 1024^4 Then
t1      = FormatNumber(siz / 1024^3, 1) & "GB" '  Gigabyte
Elseif siz < 1024^5 then
t1      = FormatNumber(siz / 1024^4, 1) & "TB" '  Terabyte
Elseif siz < 1024^6 then
t1      = FormatNumber(siz / 1024^5, 1) & "PB" '  Petabyte
Elseif siz < 1024^7 then
t1      = FormatNumber(siz / 1024^6, 1) & "EB" '  Exabyte
Elseif siz < 1024^8 then
t1 = FormatNumber(siz / 1024^7, 1) & "ZB" '  Zettabyte
'Elseif siz < 1024^9 then
' t1     = FormatNumber(siz / 1024^8, 1) & "YB" '  Yottabyte
Else
t1      = FormatNumber(siz / 1024^8, 1) & "YB" '  Yottabyte
End If
FileSize_Formatted  = t1
End Function

FullFilePath, orFileSize, Formatted

Views 622 Downloads 229

'FSO', 'Filelen', 'length', 'size', 'file size', 'filesize', 'giga', 'mega', 'tera', 'byte', 'kilo'

ANmarAmdeen
326
File System Classic ASP
Revisions

v2.0

Needs