Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


File Size Function

 
Logged in as: Guest
arrSession:exec spGetSession 2,16,34874
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> Post a VBScript >> File Size Function
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 File Size Function - 5/25/2006 6:12:53 AM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
It seems like I'm always messing with file size conversions so I wrote a quick function to dynamically convert bytes to other sizes and add on the size at the end.

Function fsize(num)
'this function assumes bytes are fed in
lvl = Len(num)
If lvl < 6 then
num = num/1024
fsize = " KB"
Elseif lvl < 9 then
num = (num/1024)/1024
fsize = " MB"
Elseif lvl < 13 Then
num = ((num/1024)/1024)/1024
fsize = " GB"
Else
num = (((num/1024)/1024)/1024)/1024
fsize = " TB"
End If
fsize = Round(num,2) & fsize
End Function

function in action:
WScript.Echo fsize(22134568964234)
wscript.Echo fsize(2213456896)
wscript.Echo fsize(221)
wscript.Echo fsize(2213456)

output:
20.13 TB
2.06 GB
0.22 KB
2.11 MB

< Message edited by kirrilian -- 5/30/2006 3:45:01 PM >


_____________________________

Have you searched here ?
VBScript Fundamentals
My Site
 
 
Revisions: 1 | Post #: 1
 
 RE: File Size Function - 5/25/2006 6:13:55 AM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
I may add the reverse conversion at some point in the future, but I need to finish the script I wrote this function for first. 

_____________________________

Have you searched here ?
VBScript Fundamentals
My Site

(in reply to kirrilian)
 
 
Post #: 2
 
 RE: File Size Function - 5/30/2006 1:06:37 PM   
  DiGiTAL.SkReAM


Posts: 1157
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
quote:

ORIGINAL: kirrilian

I may add the reverse conversion at some point in the future, but I need to finish the script I wrote this function for first. 


Whiner.

_____________________________

"Would you like to touch my monkey?" - Dieter (Mike Meyers)

"It is better to die like a tiger, than to live like a pussy."
-Master Wong, from Balls of Fury

(in reply to kirrilian)
 
 
Post #: 3
 
 RE: File Size Function - 5/30/2006 3:46:07 PM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
changed the range for GB

actually i think it would be better to just write another function to do the reverse conversion anyways



_____________________________

Have you searched here ?
VBScript Fundamentals
My Site

(in reply to DiGiTAL.SkReAM)
 
 
Post #: 4
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> Post a VBScript >> File Size Function Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts