cypher175 Posted June 12, 2010 Share Posted June 12, 2010 I have 20 txt files all with data in them, and I need to combine all data in all the files into one big 2D array... How would I do this..?? Link to comment Share on other sites More sharing options...
Developers Jos Posted June 12, 2010 Developers Share Posted June 12, 2010 Where did you get stuck in your code? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
cypher175 Posted June 12, 2010 Author Share Posted June 12, 2010 I can get an array from each file with _FileReadToArray but how do I combine all those arrays into 1 array..?? Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted June 12, 2010 Moderators Share Posted June 12, 2010 _ArrayConcatenate()? It really depends on what you are trying to do. You could: 1. Do a fileread on all the files, and dump to one file, then do a _filereadtoarray on the one file for one array 2. Continue what you're doing and use _ArrayConcatenate() 3. Do a fileread and append/concatenate each fileread to the var string $s_str &= FileRead($a_file[$i]) ( if the filereads were in a loop example ), then use StringSplit() to split the lines into one array. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
cypher175 Posted June 12, 2010 Author Share Posted June 12, 2010 with the _ArrayConcatenate() how do I combine the 1st _FileReadToArray to an empty non existent array..?? Link to comment Share on other sites More sharing options...
Tvern Posted June 12, 2010 Share Posted June 12, 2010 with the _ArrayConcatenate() how do I combine the 1st _FileReadToArray to an empty non existent array..?? Philosophers would probably be able to have a lengthy discussion contemplating if something that does not exist can be an array. The autoit interpeter is not a philosopher and wants it's arrays to exist before it will accept them as arrays. If you mean you want to combine 2 arrays into another array, while keeping the original arrays the same as before the combine, lok at this: #include <array.au3> Local $array1[4] = [0,1,2,3] Local $array2[3] = ["a","b","c"] Local $newAray = $array1 ;Just making a copy of $array1 to work with here. This way $array1 is not affected. _ArrayConcatenate($newAray,$array2) _ArrayDisplay($array1,"$array1") _ArrayDisplay($array2,"$array2") _ArrayDisplay($newAray,"$newAray") Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted June 12, 2010 Moderators Share Posted June 12, 2010 with the _ArrayConcatenate() how do I combine the 1st _FileReadToArray to an empty non existent array..?? I've personally never used the function. But I'd imagine my code would look something like this:#include <File.au3> #include <Array.au3> Global $a_filelist[11] = [ 10, _ "C:\file1", "C:\file2", "C:\file3", "C:\file4", "C:\file5", _ "C:\file6", "C:\file7", "C:\file8", "C:\file9", "C:\file10"] Global $a_lta, $a_lta_now For $ilist = 1 To $a_filelist[0] $a_lta_now = _FileListToArray($a_filelist[$ilist]) If $ilist = 1 Then $a_lta = $a_lta_now ContinueLoop EndIf _ArrayConcatenate($a_lta, $a_lta_now, 1) Next If IsArray($a_lta) Then $a_lta[0] = UBound($a_lta) - 1 EndIf _ArrayDisplay($a_lta) Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
wolf9228 Posted June 12, 2010 Share Posted June 12, 2010 (edited) OR Sorry a simple mistake, Code has been modified expandcollapse popup#include <Array.au3> $file = FileOpen("file1.txt", 2) FileWrite($file,"0123456789") FileClose($file) $file = FileOpen("file2.txt", 2) FileWrite($file,"01234567890123456789") FileClose($file) Dim $FileArray addFileName("file1.txt",$FileArray) addFileName("file2.txt",$FileArray) _ArrayDisplay($FileArray,"") _FileReadToArray2D($FileArray) _ArrayDisplay($FileArray,"") Func _FileReadToArray2D(ByRef $FileArray) if Not IsArray($FileArray) Then Return For $i = 0 To UBound($FileArray) - 1 $FileName = $FileArray[$i][0] $file = FileOpen($FileName, 0) $chars = FileRead($file) FileClose($file) $CharArray = StringSplit($chars,"") $FileArray[$i][0] &= "|cols = " & $CharArray[0] For $j = 1 To $CharArray[0] if $j >= UBound($FileArray,2) Then _ ReDim $FileArray[UBound($FileArray)][UBound($FileArray,2) + 1] $FileArray[$i][$j] = $CharArray[$j] Next Next EndFunc Func addFileName($FileName,ByRef $FileArray) if Not IsArray($FileArray) Then Dim $FileArray[1][1] $FileArray[0][0] = $FileName Else ReDim $FileArray[UBound($FileArray) + 1][1] $FileArray[UBound($FileArray) - 1][0] = $FileName EndIf EndFunc Edited June 16, 2010 by wolf9228 صرح السماء كان هنا 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