csize.mrc – Convert Size
1 2 3 4 5 | ;;;; Convert Size v1.1.0 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Written by: ;; ;; Brian Schmidt aka. brianMan. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
;;;; Readme / Help ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Load this script in mIRC, if you don’t know how to do this, then perhaps ;;
;; you shouldn’t be using this script. ;;
;; ;;
;; This script is used to convert size in bytes to a nice to KB/MB/GB etc. ;;
;; ;;
;; There are 2 ways to use this scripts: ;;
;; 1. Message to active window with /csize: ;;
;; “/csize /csize 54653875238″ ;;
;; Will output: ;;
;; “50.9 GB” ;;
;; 2. Can also be used for in-line reverse with $rev in scripts etc. ;;
;; “//echo -a Converting 54653875238 bytes to $csize(54653875238).ext ;;
;; gives $csize(54653875238) $csize(54653875238).ext” ;;
;; Will output: ;;
;; “Converting 54653875238 bytes to GB gives 50.900388 GB” ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; Changelog ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; v1.1.1 ;;
;; * Fixed $csize().ext always returning YiB ;;
;; ;;
;; v1.1.0 ;;
;; + Added posiblitiy to convert to a specific type with identifiers. ;;
;; $csize(50000000) returns 47.683716 (MiB) ;;
;; $csize(50000000).gib returns 0.046566 (GiB) ;;
;; This can’t be done with the “b” property, wich is also irrelevant, since ;;
;; the Bytes is allready what you have. ;;
;; ;;
;; v1.0.0 ;;
;; + Initial release. ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
alias csize {
if ($len($$1) <= 3) {
var %csize $$1
var %csize.ext B
}
if ($len($$1) > 3 || ($prop != $null && $prop == kib)) {
var %csize $calc( $$1 / 1024 )
var %csize.ext KiB
if ($prop == kib) return %csize
}
if ($len($$1) > 6 || ($prop != $null && $prop == mib)) {
var %csize $calc( %csize / 1024 )
var %csize.ext MiB
if ($prop == mib) return %csize
}
if ($len($$1) > 9 || ($prop != $null && $prop == gib)) {
var %csize $calc( %csize / 1024 )
var %csize.ext GiB
if ($prop == gib) return %csize
}
if ($len($$1) > 12 || ($prop != $null && $prop == tib)) {
var %csize $calc( %csize / 1024 )
var %csize.ext TiB
if ($prop == tib) return %csize
}
if ($len($$1) > 15 || ($prop != $null && $prop == pib)) {
var %csize $calc( %csize / 1024 )
var %csize.ext PiB
if ($prop == pib) return %csize
}
if ($len($$1) > 18 || ($prop != $null && $prop == eib)) {
var %csize $calc( %csize / 1024 )
var %csize.ext EiB
if ($prop == eib) return %csize
}
if ($len($$1) > 21 || ($prop != $null && $prop == zib)) {
var %csize $calc( %csize / 1024 )
var %csize.ext ZiB
if ($prop == zib) return %csize
}
if ($len($$1) > 24 || ($prop != $null && $prop == yib)) {
var %csize $calc( %csize / 1024 )
var %csize.ext YiB
if ($prop == yib) return %csize
}
if ($isid == $true) {
if ($prop == ext) {
return %csize.ext
}
return %csize
}
else {
msg $active $round(%csize,2) %csize.ext
}
}