nago Posted January 24, 2009 Share Posted January 24, 2009 I'm having a bit of a blonde moment again, I was hoping someone here could clear this up for me. I have an array with 40,000+ entries (It's a file list returned from _FileListToArray()) but only one column (With the filenames in them.) I want to go ahead and add additional columns to this array so I can add some statistics about the files to them, but I have no idea how to add that additional column. I looked up ReDim, but when trying to use it to resize my array, it wipes out all the data within it. Can anyone give me a pointer as to the correct usage of ReDim in this circumstance? Link to comment Share on other sites More sharing options...
Authenticity Posted January 24, 2009 Share Posted January 24, 2009 (edited) #include <file.au3> Opt('MustDeclareVars', 1) Dim $ArrFiles, $ArrFiles2, $nEntries, $ntmp, $txt = '' $ArrFiles = _FileListToArray(@ScriptDir) For $nEntries = 1 To $ArrFiles[0] $txt &= $ArrFiles[$nEntries] & @CRLF Next MsgBox(64, 'Title', $txt & @CRLF & @CRLF & $ArrFiles[0]) $ArrFiles2 = _FileListToArray('C:\WINDOWS', '*.exe') ReDim $ArrFiles[$ArrFiles2[0]+$ArrFiles[0]] $ntmp = 0 For $nEntries = $ArrFiles[0] To UBound($ArrFiles)-1 $ntmp += 1 $ArrFiles[$nEntries] = $ArrFiles2[$ntmp] Next $ArrFiles[0] += $ArrFiles2[0]-1 $txt = '' For $nEntries = 1 To $ArrFiles[0] $txt &= $ArrFiles[$nEntries] & @CRLF Next MsgBox(64, 'Title', $txt & @CRLF & @CRLF & $ArrFiles[0]) Exit Don't get confuse with this script all you need to know that ReDim just let you reallocate or reference your array to suit your needs, like more subscripts which old ones retain their values or change how metrics' columns or rows get reference, i.e. $Arr[10][20] ---> ReDim $Arr[5][40] etc.. Edited January 24, 2009 by Authenticity Link to comment Share on other sites More sharing options...
Raupi Posted January 24, 2009 Share Posted January 24, 2009 Try This : #include <File.au3> #include <Array.au3> Opt('MustDeclareVars', 1) Dim $ArrFiles $ArrFiles = _FileListToArray(@ScriptDir) _ArrayDisplay($ArrFiles) $ArrFiles = _ArrayAdd_Column($ArrFiles) _ArrayDisplay($ArrFiles) $ArrFiles = _ArrayAdd_Column($ArrFiles) _ArrayDisplay($ArrFiles) Func _ArrayAdd_Column($Array) Local $aTemp[UBound($Array)][UBound($Array, 0) + 1] For $i = 0 To UBound($Array) - 1 For $j = 0 To UBound($Array, 0) - 1 If UBound($Array, 0) = 1 Then $aTemp[$i][0] = $Array[$i] If UBound($Array, 0) > 1 Then $aTemp[$i][$j] = $Array[$i][$j] Next Next Return $aTemp EndFunc ;==>_ArrayAdd_Column Link to comment Share on other sites More sharing options...
nago Posted January 24, 2009 Author Share Posted January 24, 2009 Very Keen, Raupi: Thank You. I guess that means there is no "built-in" way of doing this then, though. Thanks for the tip. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now