I've written a script to scan users homedirectories on size, sort them by size (biggest on top) and write the 10 biggest folders to a textfile.
To do this, first DirPlus UDF scannes all folders and QuickSort UDF sorts them out by size, biggest on top.

Problem is that the results are false. It doesn't return the top-10 of biggest folders, but returns 10 folders randomly. Not even the biggest or smalles are mentioned, just random folders witch are sorted by size.

Variable $HomeDirsLocation is defined earlier in my script. The textfile to write to is also already opened earlier.

Code:
BREAK ON
call 'quicksort.udf'
call 'dirplus.udf'

WRITELINE (1, "Gebruik van de HomeDirs TOP-10" + @CRLF)
WRITELINE (1, "------------------------------------" + @CRLF)


$root = dirplus('$HomeDirsLocation','/ad')

DIM $folders[ubound($root)]

FOR $i = 0 to ubound($root)
$n = $root[$i].name
$s = val($root[$i].size)
$folders[$i] = $n,$s
NEXT

$folders = quicksort($folders,1)


$iLimit=UBound($Folders)-9
If $iLimit<9 $iLimit=UBound($Folders) EndIf
FOR $i = UBound($folders) To $iLimit Step -1
$item=$folders[$i]
$item[0]+" "+$item[1]+@CRLF
$=WriteLine(1, $item[0] + chr(009) + chr(009) + FormatNumber (CDbl($item[1]/1024/1024),0) + " MB" + @CRLF)
NEXT


WRITELINE (1, @CRLF + @CRLF + @CRLF + @CRLF)



I don't understand what I'm doing wrong. Can someone help me please ?