Jump to content

File Size Converter


Endgame
 Share

Recommended Posts

Just a quick UDF that I threw together. It takes a value in bytes and converts it to the appropriate value and units.

Func _FileSizeConvert($bytes,$rounding = 2, $outputstring = True)

    Local $array[3]
    
    Select
        Case $bytes < 2^10 ;bytes
            $array[0] = $bytes
            $array[1] = "bytes"
            $array[2] = "bytes"
        Case $bytes >= 2^10 and $bytes < 2^20 ;kilobytes
            $array[0] = Round($bytes/2^10,$rounding)
            $array[1] = "kilobytes"
            $array[2] = "KB"
        Case $bytes >= 2^20 and $bytes < 2^30 ;megabytes
            $array[0] = Round($bytes/2^20,$rounding)
            $array[1] = "megabytes"
            $array[2] = "MB"
        Case $bytes >= 2^30 and $bytes < 2^40 ;gigabytes
            $array[0] = Round($bytes/2^30,$rounding)
            $array[1] = "gigabytes"
            $array[2] = "GB"
        Case $bytes >= 2^40 and $bytes < 2^50 ;terabytes
            $array[0] = Round($bytes/2^40,$rounding)
            $array[1] = "terabytes"
            $array[2] = "TB"
        Case $bytes >= 2^50 and $bytes < 2^60 ;petabytes
            $array[0] = Round($bytes/2^50,$rounding)
            $array[1] = "petabytes"
            $array[2] = "PB"
        Case $bytes >= 2^60 and $bytes < 2^70 ;exabytes
            $array[0] = Round($bytes/2^60,$rounding)
            $array[1] = "exabytes"
            $array[2] = "EB"
        Case $bytes >= 2^70 and $bytes < 2^80 ;zettabytes
            $array[0] = Round($bytes/ 2^70,$rounding)
            $array[1] = "zettabytes"
            $array[2] = "ZB"
        Case $bytes >= 2^80 ;yottabytes
            $array[0] = Round($bytes/ 2^80,$rounding)
            $array[1] = "yottabytes"
            $array[2] = "YB"
    EndSelect
    
    If $outputstring then 
        Return $array[0] & " " & $array[2]
    Else
        Return $array
    EndIf
    
EndFuncoÝ÷ Øw«z+ìZ^¡ø­²ë殶­sdFÒb33c´fÆU6¦P ¤bfÆTW7G2gV÷C´3¢b3#·vVfÆRç72gV÷C²FVà b33c´fÆU6¦RÒfÆTvWE6¦RgV÷C´3¢b3#·vVfÆRç72gV÷C² ×6t&÷ÂgV÷C·vVfÆRç72gV÷C²ÂgV÷C·vVfÆRç722gV÷C²fײb33c´fÆU6¦RfײgV÷C²'FW2÷"gV÷C²fײôfÆU6¦T6öçfW'Bb33c´fÆU6¦RfײgV÷C²âgV÷C²¤VÇ6P ×6t&÷ÂgV÷C·vVfÆRç72Ö76ærgV÷C²ÂgV÷C´3¢b3#·vVfÆRç72æ÷BfÆ&ÆRgV÷C²¤VæD

Convert.au3

I know it is not rocket science but it sure beats dividing by 1000 or 1000000 or 1000000000 in my head to get the wrong answer!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...