Jump to content

Recommended Posts

Posted

Function to dynamically format (file) size to kB/MB/GB/TB:

Func FormatFileSize($iSizeInBytes)

  Local $iSize, $i

  $iSize = $iSizeInBytes
  $i = 0
  While $iSize >= 1024 ;split value, you can set lower number like 900 for earlier switch (0.98 MB)
    $iSize /= 1024 ;this must be always 1024
    $i += 1
  WEnd

  $iSize = Round($iSize, 1) & " "; enter how many decimals you want, here it's '1'

  Switch $i
    Case 1
      $iSize = $iSize & "k"
    Case 2
      $iSize = $iSize & "M"
    Case 3
      $iSize = $iSize & "G"
    Case 4
      $iSize = $iSize & "T"
  EndSwitch

  Return $iSize & "B"

EndFunc
Posted (edited)

And this too >>

Func _ByteSuffix($iBytes, $iRound = 2) ; By Spiff59
    Local $A, $aArray[9] = [" B", " KB", " MB", " GB", " TB", " PB", "EB", "ZB", "YB"]
    While $iBytes > 1023
        $A += 1
        $iBytes /= 1024
    WEnd
    Return Round($iBytes, $iRound) & $aArray[$A]
EndFunc   ;==>_ByteSuffix

And in WinAPIEx.au3 there is _WinAPI_StrFormatByteSize().

Cheers for adding to the Examples Forum though :)

Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

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
  • Recently Browsing   0 members

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