I think the answer Doc gave is working. I tested it here.
Code:
If NOT @LOGONMODE
Break On
Else
Break Off
EndIf
Dim $RC
;$RC = SetOption("Explicit","On")
;$RC = SetOption("NoVarsInStrings","On")
;$RC = SetOption("NoMacrosInStrings","On")
;$RC = SetOption("WrapAtEOL","On")
$root = dirplus('C:\Program Files','/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)
;For Each $item In $folders
; ? $item[0] " " $item[1]
;Next
;For $i = Ubound($folders) To 0 Step -1
For $i = Ubound($folders) To (Ubound($folders)-10) Step -1
$item=$folders[$i]
$item[0]+" "+$item[1]+@CRLF
Next
Function DirPlus($path,optional $Options, optional $f, optional $sfflag)
If NOT VarType($f) Dim $f EndIf
If NOT VarType($sfflag) Dim $sfflag EndIf
Dim $file, $i, $temp, $item, $ex1, $mask,$mask1,$maskArray,$maskarray1,
$ex2, $code, $CodeWeight, $targetWeight, $weight, $masktrue
Dim $tarray[0]
$ex1 = SetOption(Explicit,on)
$ex2 = SetOption(NoVarsInStrings,on)
$codeWeight = 0
If NOT Exist($path)
$temp = SetOption(Explicit,$ex1)
$temp = SetOption(NoVarsInStrings,$ex2)
Exit @ERROR
EndIf
If NOT VarType($f)
$f = CreateObject("Scripting.FileSystemObject").getfolder($path)
EndIf
If @ERROR
$temp = SetOption(Explicit,$ex1)
$temp = SetOption(NoVarsInStrings,$ex2)
Exit @ERROR
EndIf
For Each $temp In Split($options,"/")
$temp=Trim($temp)
Select
Case Left($temp,1) = "s"
If NOT VarType($sfflag)
If Val(Right($temp,-1)) = 0
$sfflag = -1
Else
$sfflag = Val(Right($temp,-1))
EndIf
EndIf
Case Left($temp,1) = "a"
Select
Case Right($temp,-1)="d"
$codeWeight = $codeWeight + 1
$temp = "if $file.attributes & 16 " ;"if $file.type = 'File Folder' "
Case Right($temp,-1)="-d"
$codeWeight = $codeWeight + 1
$temp = "if ($file.attributes & 16)=0 " ;"if $file.type <> 'File Folder' "
Case Right($temp,-1)="s"
$codeWeight = $codeWeight + 1
$temp = "if $file.attributes & 4 "
Case Right($temp,-1)="-s"
$codeWeight = $codeWeight + 1
$temp = "if ($file.attributes & 4)=0 "
Case Right($temp,-1)="h"
$codeWeight = $codeWeight + 1
$temp = "if $file.attributes & 2 "
Case Right($temp,-1)="-h"
$codeWeight = $codeWeight + 1
$temp = "if ($file.attributes & 2)=0 "
Case Right($temp,-1)="r"
$codeWeight = $codeWeight + 1
$temp = "if $file.attributes & 1 "
Case Right($temp,-1)="-r"
$codeWeight = $codeWeight + 1
$temp = "if ($file.attributes & 1)=0 "
Case Right($temp,-1)="a"
$codeWeight = $codeWeight + 1
$temp = "if $file.attributes & 32 "
Case Right($temp,-1)="-a"
$codeWeight = $codeWeight + 1
$temp = "if ($file.attributes & 32)=0 "
EndSelect
$code = $temp + "$weight=$weight+1 endif" +@CRLF + $code
Case Left($temp,1) = "m"
$maskarray = Split(Right($temp,-2),"|")
$codeweight = $codeweight + 1
$code = "$masktrue=0 for Each $mask in $maskarray if instr($file.name,$mask) $masktrue=1 " +
"EndIf Next If $masktrue $weight=$weight+1 endif" + @CRLF +$code
Case Left($temp,1) = "f"
$maskarray1 = Split(Right($temp,-2)," ")
$codeweight = $codeweight + 1
$code = "$masktrue=0 for Each $mask1 in $maskarray1 if substr($file.name,Instrrev($file.name,'.')+1)" +
"=$mask1 $masktrue=1 EndIf Next If $masktrue $weight=$weight+1 endif" + @CRLF +$code
EndSelect
Next
$code = "$weight = 0 $targetWeight = " + $codeweight + @CRLF + $code
$code = $code + "if $weight = $targetweight Exit 1 endif"
For Each $file In $f.subfolders
If Execute($code)
$tarray[$i] = $file
$i = $i + 1
ReDim preserve $tarray[$i]
EndIf
If $sfflag
$temp = dirplus($file,$options,$file,$sfflag-1)
For Each $item In $temp
$tarray[$i] = $item
$i = $i + 1
ReDim preserve $tarray[$i]
Next
EndIf
Next
For Each $file In $f.files
If Execute($code)
$tarray[$i] = $file
$i = $i + 1
ReDim preserve $tarray[$i]
EndIf
Next
If $i
ReDim preserve $tarray[$i-1]
$i=0
Else
$tarray = 0
EndIf
$dirplus = $tarray
$temp = SetOption(Explicit,$ex1)
$temp = SetOption(NoVarsInStrings,$ex2)
Exit @ERROR
EndFunction
Function quicksort($a, optional $indexcol )
;$a array to be sorted
;$indexcol index of subitem to sort on
;$LowerIndexStack lower index stack
;$UpperIndexStack upper index stack
;$StackPointer stack pointer
;$LowerIndex lower index
;$UpperIndex upper index
;$Pivot value of pivot
;$TempSwappingValue temp variable for swapping elements
;$index stores either lower or upper index of unsorted segment of the array
;$i counter moving from lower index to the right
;$j counter moving from upper index to the left
;$LowerItem value to compare with
Dim $StackSize, $StackIncr
$StackSize = 8
$StackIncr = $StackSize
Dim $LowerIndexStack[$StackSize],$UpperIndexStack[$StackSize]
Dim $StackPointer, $LowerIndex, $UpperIndex, $Pivot, $TempSwappingValue, $index, $i, $j, $LowerItem
Dim $ExitLoop
If $indexcol
$indexcol = CStr($indexcol)
If indexcol < 0
$indexcol = 0
EndIf
Else
$indexcol = 0
EndIf
$LowerIndexStack[0]=0
$UpperIndexStack[0]=Ubound($a)
$StackPointer=0
While $StackPointer >= 0
$LowerIndex=$LowerIndexStack[$StackPointer]
$UpperIndex=$UpperIndexStack[$StackPointer]
While $LowerIndex < $UpperIndex
$Pivot=$LowerIndex+($UpperIndex-$LowerIndex)/2
$TempSwappingValue=$a[$LowerIndex]
$A[$LowerIndex]=$A[$Pivot]
$A[$Pivot]=$TempSwappingValue
$i=$LowerIndex+1
$j=$UpperIndex
$ExitLoop=0
Do
$LowerItem = QuickSortItem( $A[$LowerIndex],$indexcol )
While ($i<$j) AND ( QuickSortItem( $A[$i],$indexcol ) < $LowerItem)
$i=$i+1
Loop
While ($j>=$i) AND ($LowerItem < QuickSortItem( $A[$j],$indexcol ))
$j=$j-1
Loop
If $i>=$j
$ExitLoop=1
Else
$TempSwappingValue=$A[$i]
$A[$i]=$A[$j]
$A[$j]=$TempSwappingValue
$j=$j-1
$i=$i+1
EndIf
Until $ExitLoop=1
$TempSwappingValue=$a[$LowerIndex]
$a[$LowerIndex]=$a[$j]
$a[$j]=$TempSwappingValue
$index=$j
If $index - $LowerIndex <= $UpperIndex - $index
If $index+1 < $UpperIndex
If $StackPointer>$StackSize
$StackSize = $StackSize + $StackIncr
ReDim preserve $LowerIndexStack[$StackSize]
ReDim preserve $UpperIndexStack[$StackSize]
EndIf
$LowerIndexStack[$StackPointer]=$index+1
$UpperIndexStack[$StackPointer]=$UpperIndex
$StackPointer=$StackPointer+1
EndIf
$UpperIndex=$index-1
Else
If $index-1 > $LowerIndex
If $StackPointer>$StackSize
$StackSize = $StackSize + $StackIncr
ReDim preserve $LowerIndexStack[$StackSize]
ReDim preserve $UpperIndexStack[$StackSize]
EndIf
$LowerIndexStack[$StackPointer]=$LowerIndex
$UpperIndexStack[$StackPointer]=$index-1
$StackPointer=$StackPointer+1
EndIf
$LowerIndex=$index+1
EndIf
Loop
$StackPointer=$StackPointer-1
Loop
$quicksort=$a
EndFunction
Function QuickSortItem( $value, $index )
If VarType($value) & 8192
If ($index <= Ubound($value))
$QuickSortItem = $value[$index]
Else
$QuickSortItem = ""
EndIf
Else
$QuickSortItem = $value
EndIf
EndFunction