goldenix Posted September 16, 2009 Share Posted September 16, 2009 (edited) I have a files inside a folder & like to read each file in a separate array so I can arraysearch all arrays. This is what aI have so far. #include <Array.au3> #include <file.au3> Global $Array_n = 1 $FILE = 'New Text document.txt' __FileReadToArray($FILE) $FILE = 'New Text document.txt' __FileReadToArray($FILE) Func __FileReadToArray($FILE) Dim $aRecords[$Array_n] If Not _FileReadToArray($FILE,$aRecords[$Array_n]) Then MsgBox(4096,"Error", " Error reading file to Array error:" & @error) Exit EndIf $Array_n = $Array_n +1 _ArrayDisplay($aRecords[$Array_n] ,"$FileList 1") EndFunc Edited September 17, 2009 by goldenix My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list] Link to comment Share on other sites More sharing options...
Juvigy Posted September 16, 2009 Share Posted September 16, 2009 I think you need "Redim" . Check it in the help file.There are examples. Link to comment Share on other sites More sharing options...
jvanegmond Posted September 16, 2009 Share Posted September 16, 2009 If Not _FileReadToArray($FILE,$aRecords[$Array_n]) Then You can't do this ($aRecords[$Array_n]), work around it . : ) github.com/jvanegmond Link to comment Share on other sites More sharing options...
goldenix Posted September 16, 2009 Author Share Posted September 16, 2009 (edited) If Not _FileReadToArray($FILE,$aRecords[$Array_n]) Then You can't do this ($aRecords[$Array_n]), work around it . : ) How can I work around if I dont know how to make an array? All i know is how to add rows & colums to an array. Ok, lets forget the Example above. Its a bad example. hire is a better one: (How do you make 3 arrays ?) #include <Array.au3> For $i = 1 to 3 _ArrayAdd($avArray & $i, "Brian " & $i) Next _ArrayDisplay($avArray1,"") _ArrayDisplay($avArray2,"") _ArrayDisplay($avArray3,"") Edited September 16, 2009 by goldenix My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list] Link to comment Share on other sites More sharing options...
jvanegmond Posted September 16, 2009 Share Posted September 16, 2009 I see you've never worked with arrays before .. I'm not sure whether you wanted to create one array with 3 elements or 3 arrays with 3 elements.. Here's what I think you're looking for and something I know will help you: #include <Array.au3> Dim $avArray[3] For $i = 0 to 2 $avArray[$i] = "Brian" & $i Next _Display($avArray[0]) _Display($avArray[1]) _Display($avArray[2]) Func _Display($s) MsgBox(0, "Display", $s) EndFunc github.com/jvanegmond Link to comment Share on other sites More sharing options...
goldenix Posted September 17, 2009 Author Share Posted September 17, 2009 (edited) I see you've never worked with arrays before .. I'm not sure whether you wanted to create one array with 3 elements or 3 arrays with 3 elements.. Here's what I think you're looking for and something I know will help you: I want to create 3 arrays with 3 elements (or 1 element in each array as an example). But you see I cant use this method (see below) because I want to read each file inside the folder, into a different array. So I can perform array search inside all arrays. And this means I do not know forehead how many arrays I will need. This is how I make arrays: But I cant use this method in current case: Dim $avArray1[1] ;1 Row Dim $avArray2[1] ;1 Row Dim $avArray3[1] ;1 Row For $x = 1 To 10 $iRow1 = UBound($avArray1) ;add Rows $iRow2 = UBound($avArray2) ;add Rows $iRow3 = UBound($avArray3) ;add Rows ReDim $avArray1[$iRow1 + 1] ; add row ReDim $avArray2[$iRow2 + 1] ; add row ReDim $avArray3[$iRow3 + 1] ; add row $avArray1[$x] = $x $avArray2[$x] = $x $avArray3[$x] = $x Next _ArrayDisplay($avArray1, "$avArray1") _ArrayDisplay($avArray2, "$avArray2") _ArrayDisplay($avArray3, "$avArray3") Edited September 17, 2009 by goldenix My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list] Link to comment Share on other sites More sharing options...
Juvigy Posted September 17, 2009 Share Posted September 17, 2009 You only need one array. You can create it like this: Dim $avArray[1] That array contains only one element - $avArray[0] When you start searching the folder and find a file you do: Redim $avArray[Ubound($avArray)+1] Which adds a new empty element at the end of the array.Then you fill that element whit your search result like: $avArray[Ubound($avArray)-1]="the file you found" Put all that in a loop for searching files and you are done. Link to comment Share on other sites More sharing options...
99ojo Posted September 17, 2009 Share Posted September 17, 2009 (edited) You only need one array. You can create it like this: Dim $avArray[1] That array contains only one element - $avArray[0] When you start searching the folder and find a file you do: Redim $avArray[Ubound($avArray)+1] Which adds a new empty element at the end of the array.Then you fill that element whit your search result like: $avArray[Ubound($avArray)-1]="the file you found" Put all that in a loop for searching files and you are done. Hi, maybe this is what you want. Create one array with one column for every text file and rows with the lines of the text file: #include <Array.au3> #include <file.au3> $count = 0 $path = "c:\temp" ;get textfiles in given $path $files = _FileListToArray ($path, "*.txt", 1) ;Get lines of textfiles, get the highest value For $i = 1 To UBound ($files) - 1 $counttemp = _FileCountlines ($path & "\" & $files [$i]) If $counttemp > $count Then $count = $counttemp EndIf Next ;create array -> [lines] [textfiles] Dim $myArray [$count + 2][UBound ($files)] ;fill array with textlines For $i = 1 To UBound ($files) - 1 $j = 0 $myArray [$j] [$i] = $files[$i] $file = FileOpen ($path & "\" & $files [$i], 0) If $file = -1 Then ContinueLoop While 1 $j += 1 $line = FileReadLine ($file) If @error = -1 Then ExitLoop $myArray [$j] [$i] = $line WEnd FileClose ($file) Next _ArrayDisplay ($myArray) ;-)) Stefan Edit: Code change Edited September 17, 2009 by 99ojo Link to comment Share on other sites More sharing options...
goldenix Posted September 17, 2009 Author Share Posted September 17, 2009 @99jojo your code gets stuck in the end. it is caused by _ArrayDisplay ($myArray). But it works if you remove that line. so thanx My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list] 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