satnad Posted October 24, 2007 Share Posted October 24, 2007 I have a text file that is 15224 lines long. I am searching for a certain four character string within the whole document. I can confirm that the document scans to line 7424 but does not appear to pick up this character string after line 7424. Is there a line length or character length restriction or is there something else that I need to do. Thanks. Link to comment Share on other sites More sharing options...
weaponx Posted October 24, 2007 Share Posted October 24, 2007 How are you opening the file? With FileOpen? Or are you using FileReadToArray Link to comment Share on other sites More sharing options...
satnad Posted October 24, 2007 Author Share Posted October 24, 2007 How are you opening the file? With FileOpen? Or are you using FileReadToArrayHere is a copy of my script.$FileFound = FileOpen ("FileFound.txt", 1)$TimeStart = ( "Start" & " " & @YEAR & @MON & @MDAY & " " & @HOUR & @MIN & @SEC)FileWrite ( $FileFound, $TimeStart & @CRLF)For $D = 1 to 15224 Step 1 $insert = "" $text = FileReadLine("C:\Documents and Settings\satnad\Desktop\newattempt7NORTH.txt", $D)If StringInStr ( $text, "22c8") then FileWrite ( $FileFound, $insert & $text & "North" & @CRLF)Next$TimeStop = ( "Stop" & " " & @YEAR & @MON & @MDAY & " " & @HOUR & @MIN & @SEC)FileWrite ( $FileFound, $TimeStop & @CRLF)FileClose($FileFound)exit Link to comment Share on other sites More sharing options...
ChrisL Posted October 24, 2007 Share Posted October 24, 2007 Try this $FileFound = FileOpen ("FileFound.txt", 1) $TimeStart = ( "Start" & " " & @YEAR & @MON & @MDAY & " " & @HOUR & @MIN & @SEC) FileWrite ( $FileFound, $TimeStart & @CRLF) ;Read the whole file to a variable $fhandle = FileOpen("C:\Documents and Settings\satnad\Desktop\newattempt7NORTH.txt", 0) $alltext = FileRead($fhandle) FileClose($fhandle) ;split the text in to an array $alltextArray = StringSplit($alltext,@crlf,1) ;loop through the array (each line of text) For $i = 1 to Ubound($alltextArray) -1 $Insert=""; Mo idea why you have this because it is always blank! If StringInStr ($alltextArray[$i], "22c8") then FileWrite ( $FileFound, $insert & $alltextArray[$i] & "North" & @CRLF) Next $TimeStop = ( "Stop" & " " & @YEAR & @MON & @MDAY & " " & @HOUR & @MIN & @SEC) FileWrite ( $FileFound, $TimeStop & @CRLF) FileClose($FileFound) exit [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
satnad Posted October 25, 2007 Author Share Posted October 25, 2007 Try this $FileFound = FileOpen ("FileFound.txt", 1) $TimeStart = ( "Start" & " " & @YEAR & @MON & @MDAY & " " & @HOUR & @MIN & @SEC) FileWrite ( $FileFound, $TimeStart & @CRLF) ;Read the whole file to a variable $fhandle = FileOpen("C:\Documents and Settings\satnad\Desktop\newattempt7NORTH.txt", 0) $alltext = FileRead($fhandle) FileClose($fhandle) ;split the text in to an array $alltextArray = StringSplit($alltext,@crlf,1) ;loop through the array (each line of text) For $i = 1 to Ubound($alltextArray) -1 $Insert=""; Mo idea why you have this because it is always blank! If StringInStr ($alltextArray[$i], "22c8") then FileWrite ( $FileFound, $insert & $alltextArray[$i] & "North" & @CRLF) Next $TimeStop = ( "Stop" & " " & @YEAR & @MON & @MDAY & " " & @HOUR & @MIN & @SEC) FileWrite ( $FileFound, $TimeStop & @CRLF) FileClose($FileFound) exit ChrisL: Tried your script. It keeps giving me an error at the line "$alltext = FileRead($fhandle)" saying there is an Incorrect number of parameters in the function call. If I change this line to say "$alltext = FileRead($fhandle, 64000)" it searches great but I would then have to check the number of characters each in file I want to check and edit the script accordingly. As far as the $Insert = "", this is just a piece of a scipt I am writing. I have narrowed my problem down to this section and this $Insert can be eliminated from this segment of script for now. You have solved my problem with this script and I thank you for that, any suggestion as how to get rid of the last error of Incorrect number of parameters? I looked in the help and it is asking for the number of characters to be read and there doesn't seem to be an option to read the entire file. Satnad Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted October 25, 2007 Moderators Share Posted October 25, 2007 Just use _FileReadToArray() as suggested... you won't have to read every line individually as they will all be read and put in an array, then just loop through the array as you're doing above... No fuss no muss. 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...
randallc Posted October 25, 2007 Share Posted October 25, 2007 ChrisL: Tried your script. It keeps giving me an error at the line "$alltext = It keeps giving me an error at the line "$alltext = FileRead($fhandle)" saying there is an Incorrect number of parameters in the function callHi,Strange;Please post an example txt file where this occurs.Maybe check you have latest version of AutoIt; ; ? what number/ There was an error in one version some time back with fileread.Best, randall ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW 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