keke Posted March 6, 2008 Share Posted March 6, 2008 how can i use FileRead with FileReadLine to start reading from the last line of my text file and after it has read from the last line continue to only read new text? Please let me know if you don't understand what im asking. thanks Link to comment Share on other sites More sharing options...
james3mg Posted March 6, 2008 Share Posted March 6, 2008 how can i use FileRead with FileReadLine to start reading from the last line of my text file and after it has read from the last line continue to only read new text?Please let me know if you don't understand what im asking.thanksHow about showing what code you've already tried?You might FileRead() a previously FileOpen()'ed file so the 'next' line would be EOF by default...then run FileReadLine() (with no line parameter) and if @error is -1, then no lines have been added. Otherwise, you'll get the new line. Be sure to keep that up until you reach EOF again, or you'll miss it if multiple lines are added at a time.Just a thought. "There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110 Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted March 6, 2008 Moderators Share Posted March 6, 2008 ;_FileLastLineContinue will return all the text from the last line on after the first pass ;$nLastSize will check to see if the file size has changed before it even reads the file (save on resources) Global $sText, $nLastSize, $nCurrentSize, $nLastLine = 0 Global $hFileToRead = "Put File Name Here" While 1 $nCurrentSize = FileGetSize($hFileToRead) If $nCurrentSize <> $nLastSize Then $nLastSize = $nCurrentSize $sText = _FileLastLineContinue($hFileToRead) ;$sText now has all the data from the last file read to the current EndIf Sleep(1000);Sleep 1 second WEnd Func _FileLastLineContinue($hFile) Local $aArray = StringSplit(StringStripCR(FileRead($hFile)), @LF) Local $sHoldText For $i = ($nLastLine + 1) To $aArray[0] $sHoldText &= $aArray[$i] & @CRLF Next $nLastLine = $aArray[0] Return StringTrimRight($sHoldText, 2) EndFunc 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...
keke Posted March 6, 2008 Author Share Posted March 6, 2008 Thanks a million. Link to comment Share on other sites More sharing options...
keke Posted March 7, 2008 Author Share Posted March 7, 2008 (edited) With thorough testing it seems as if it is reading the whole file, opposed to starting from the end and continuing from there... $sDate = @YEAR & @MON & @MDAY Global $sText, $nLastSize, $nCurrentSize, $nLastLine = 0 If WinExists("My App Window", "" ) Then $buddy = StringSplit($varBuddies, ";") ; Splits string into individual names $var = WinList("[CLASS:FTC_VIEWAllTab]", "") For $a = 1 To $var[0][0] $newstring = StringReplace($var[$a][0], "/", "-") ; Replaces the '/' with '-' Global $hFileToRead = $path & "\" & "FT" & $sDate & " " & $newstring & ".txt" $nCurrentSize = FileGetSize($hFileToRead) If $nCurrentSize <> $nLastSize Then $nLastSize = $nCurrentSize $sText = _FileLastLineContinue($hFileToRead) ;$sText now has all the data from the last file read to the current EndIf For $i = 1 To $buddy[0] If StringInStr($sText, $buddy[$i]) Then MsgBox(0, "", $buddy[$i] & " is at your table!", 5) Else EndIf Next Next Else EndIf EndFunc Func _FileLastLineContinue($hFile) Local $aArray = StringSplit(StringStripCR(FileRead($hFile)), @LF) Local $sHoldText For $i = ($nLastLine + 1) To $aArray[0] $sHoldText &= $aArray[$i] & @CRLF Next $nLastLine = $aArray[0] Return StringTrimRight($sHoldText, 2) EndFunc Edited March 7, 2008 by keke Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted March 7, 2008 Moderators Share Posted March 7, 2008 That was good, guess I'll have to look closer at who is asking question from now on: http://www.autoitscript.com/forum/index.ph...st&p=487648 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...
Recommended Posts