mIRC Homepage
Posted By: Yochai /Filter to sort by size - 19/05/04 03:14 PM
There's an option to use /filter to sort numbers, but why isn't there an option to sort by Size ?
For example, if you have a list in a dialog that contains file sizes, and you want it sorted.
I use "/filter -a" and an alias I've made to sort the file sizes, but I don't see why there shouldn't be a built in options for that.
This is the alias I've made (for example):
alias sortbysize {
if ($2 = n/a) return 1
if (b !isin $2) && (K !isin $2) && (M !isin $2) && (G !isin $2) return 1
if ( ((k !isin $2) && (m !isin $2) && (g !isin $2)) && (B isin $2) ) && ( ((k isin $1) || (m isin $1) || (g isin $1)) && (B !isin $1) ) return 1
if (k isin $1) && (m isin $2) return -1
if (m isin $1) && (G isin $2) return -1
if (m isin $1) && (k isin $2) return 1
if (g isin $1) && ( (m isin $2) || (k isin $2) ) return 1
if ((K isin $1) && (K isin $2)) || ((M isin $1) && (M isin $2)) || ((G isin $1) && (G isin $2)) || $&
( ( ((K !isin $1) && (K !isin $2)) && ((M !isin $1) && (M !isin $2)) && ((G !isin $1) && (G !isin $2)) ) && (b isin $1) && (b isin $2) ) {
tokenize 32 $calc($remove($1,G,K,M,b)) $calc($remove($2,G,K,M,b))
if ($1 !isnum) return 1
return $iif($2 > $1,-1,$iif($1 > $2,1,0))
}
return -1
}
Posted By: Sais Re: /Filter to sort by size - 19/05/04 03:49 PM
While I take your point about a built-in, it would suggest that dealing with filesizes is a "major" part of mIRC, and I don't think that's true.

Anyway, why not convert both values to bytes first, and then compare:

alias getBytes {
var %bytesval = $replace($1,b,,k,* 1024,m,* 1024* 1024,g,* 1024* 1024* 1024)
return $calc(%bytesval)
}

alias sortbySize {
var %sizeA = $getBytes($1), %sizeB = $getBytes($2)
return $iif(%sizeA < %sizeB, -1, $iif(%sizeA > %sizeB, 1,0))
}

This avoids contrary cases, such as sortbySize(1025,1K) = 1 (with yours), implying that 1024 > 1025!

Of course, it also allows you to expand your $getBytes easily to include Terabytes, and anything bigger (when the time comes!).
© mIRC Discussion Forums