Hi everyone,
I'm having some trouble trying to sort a simple array containing a number, a delimiter, and some text. Example - "183942 : data". In my test defined array it works correctly, but when I use _FileListToArray to read in directory names and DirGetSize for the number _ArraySort does not sort as expected. I thought there might be some weird white space or a CR in the element so I tried using StringStripWS and StringStripCR with no success. I do a round when I put the number and text in the array so I thought that might be an issue, I rounded first and then put in array with the same results.
I am expecting the array to be sorted from lowest to highest numerically. I'm sure I am just not understanding how _ArraySort is supposed to work, please let me know if you have any advice.
This is part of a script that scans a volume, if total disk used in >90% then will grab the size of each directory, the data owners of the top 5 directories on the disk, and email them a note asking to clean up their data. If you know of a existing script that does this please point me to it.
Here is some example code that points to c:\program files and tries to sort the directory sizes with names. This example demonstrates sorting numerically does not work as I am expecting.
#Include <Array.au3>
#include <file.au3>
Dim $aDirs[1]
Dim $aDirsizeonly[1]
Dim $x, $dir, $aMixed, $aNumbers
$aMixed = _ArrayCreate("101: text", "1: text", "9224: text", "4239: text", "0: text", "1247: text")
$aNumbers = _ArrayCreate("101", "1", "9224", "4239", "0", "1247")
$dir = _FileListToArray('c:\program files', "*", 2)
If @Error=1 Then
MsgBox (16,"Error","No Folders Found.")
Exit
EndIf
For $x = 0 to UBound($dir)-1
$size = DirGetSize('c:\program files\' & $dir[$x], 1)
If IsArray($size) Then
;$size1 = Round($size[0] /1024/1024)
;_ArrayAdd($aDirs, $size1 & ' : ' & $dir[$x])
_ArrayAdd($aDirsizeonly, Round($size[0] /1024/1024, 0))
_ArrayAdd($aDirs, Round($size[0] /1024/1024, 0) & ' : ' & $dir[$x])
EndIf
Next
_ArraySort($aNumbers)
_ArrayDisplay($aNumbers, "Defined array - Numbers only. This Works!")
_ArraySort($aMixed)
_ArrayDisplay($aMixed, "Defined array - Mixed text with Numbers. This Works!")
_ArraySort($aDirsizeonly)
_ArrayDisplay($aDirsizeonly,"DirGetSize array - Dir size only. This Works!")
_ArraySort($aDirs)
_ArrayDisplay($aDirs,"DirGetSize array - Dir name with size. This Does Not Sort As Expected.")
Thanks in advance!