realshyfox Posted March 31, 2017 Posted March 31, 2017 Hy, I have an array with some values. I must search one by one the values into the text file and return the line. I have this but... expandcollapse popup#include <File.au3> #include <Array.au3> Global $aRetArray, $sFilePath Global $file = "D:\files.txt", $search _FileReadToArray("C:\032017.txt", $aRetArray) _ArrayDelete($aRetArray, 0) Global $iRows = UBound($aRetArray, $UBOUND_ROWS) _ArrayDisplay($aRetArray) Global $iLine = 0, $sLine = '' Global $hFile = FileOpen($file) If $hFile = -1 Then MsgBox(0,'ERROR','Unable to open file for reading.') Exit 1 EndIf ; find the line that has the search string While 1 $iLine += 1 $sLine = FileReadLine($hFile) If @error = -1 Then ExitLoop ; $search found in the line, now write the next 5 lines to STDOUT For $j = 0 To $iRows - 1 $search = $aRetArray[$j] If StringInStr($sLine, $search) Then For $i = $iLine To $iLine ;ConsoleWrite(FileReadLine($hFile, $i) & @CRLF) FileCopy(FileReadLine($hFile, $i), "Z:\JD\", 0) Next ExitLoop Else ConsoleWrite($search & @CRLF) EndIf Next WEnd FileClose($hFile) Learn, learn and ... learn
rootx Posted March 31, 2017 Posted March 31, 2017 (edited) Try https://www.autoitscript.com/autoit3/docs/libfunctions/_ArraySearch.htm Edited March 31, 2017 by rootx
232showtime Posted April 2, 2017 Posted April 2, 2017 (edited) its working fine in my side and I removed Exitloop to be able to write in console "C:\Test\Test7" expandcollapse popup#include <File.au3> #include <Array.au3> Global $aRetArray, $sFilePath Global $file = "C:\Test\Test7.txt", $search _FileReadToArray("C:\Test\Test6.txt", $aRetArray) ;~ _ArrayDelete($aRetArray, 0) _ArrayDisplay($aRetArray, "First") Global $iLine = 0, $sLine = '' Global $hFile = FileOpen($file) If $hFile = -1 Then MsgBox(0, 'ERROR', 'Unable to open file for reading.') Exit 1 EndIf ; find the line that has the search string While 1 $iLine += 1 $sLine = FileReadLine($hFile) If @error = -1 Then ExitLoop ; $search found in the line, now write the next 5 lines to STDOUT For $j = 0 To UBound($aRetArray) - 1 $search = $aRetArray[$j] If StringInStr($sLine, $search) Then For $i = $iLine To $iLine MsgBox(0, "", "$i=" & $i & @CRLF & "Line= " & $iLine & @CRLF & "Search= " & $search) ConsoleWrite(FileReadLine($hFile, $i) & @CRLF) FileCopy(FileReadLine($hFile, $i), "C:\Test\New folder\", 0) Next Else ConsoleWrite("SEarch Else: " & $search & @CRLF) EndIf Next WEnd FileClose($hFile) Edited April 2, 2017 by 232showtime you can do above post as well. ill get to that... i still need to learn and understand a lot of codes Correct answer, learn to walk before you take on that marathon.
kylomas Posted April 2, 2017 Posted April 2, 2017 (edited) reallyshyfox, Some questions: 1 - How big are your search arg and searched files? 2 - What if there is more than one occurrence of the search arg in the searched file? 3 - What format is the searched/search arg file? 4 - What, exactly, is your expected output? Thanks, kylomas Edited April 3, 2017 by kylomas spelling Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
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