FormatBytes()
Posted: 16 May 2014, 20:22
Usage: FormatBytes( 1048576 ) ; returns 1.00 MB
V2 specific version:
Lots of (alter)native versions available in this topic. Please peruse.
Code: Select all
FormatBytes(N) { ; By SKAN on CT5H/D351 @ tiny.cc/formatbytes
Return DllCall("Shlwapi\StrFormatByteSize64A", "Int64",N, "Str",Format("{:16}",N), "Int",16, "AStr")
}
; Usage example :
DskSts := "", FBA := 0, TNB := 0
DriveGet, List, List
Loop, Parse, List
If DllCall( "GetDiskFreeSpaceEx", "Str",A_LoopField ":\", "Int64P",FBA, "Int64P",TNB, "Ptr",0 )
DskSts .= A_LoopField ":\`t" FormatBytes( FBA ) "`t( " FormatBytes( TNB ) " )`n"
Msgbox, 64, Drive Free Space, % DskSts
V2 specific version:
Code: Select all
#Requires AutoHotkey v2.0
MsgBox FormatBytes(0x7FFFFFFFFFFFFFFF) ; 7.99 EB
FormatBytes(N) ; By SKAN for ah2 on CT5H/D68S @ autohotkey.com/r?t=3567
{
Return DllCall("Shlwapi\StrFormatByteSizeW", "int64",N, "str",Format("{:16}",""), "int",16, "str")
}
Lots of (alter)native versions available in this topic. Please peruse.