Jump to content
Sign in to follow this  
PostHistory

Filereadline wont read beyond Line 1808

Recommended Posts

PostHistory

#include <GuiConstantsEx.au3>
#include <File.au3>
#include <Constants.au3>
#include <Misc.au3>

Global $chatlog = FileOpen("C:\chat.log",0), $pos

_start()

Func _main()
While 1
$read = FileReadLine($chatlog,$pos)
ConsoleWrite($chatlog&@CR)
ConsoleWrite($read&@CR)
if stringlen($read) > 1 Then
ConsoleWrite($read&@cr)
$pos += 1
EndIf
ConsoleWrite($pos&@cr)
FileClose($chatlog)
WEnd

EndFunc

Func _start()
    FileSetPos($chatlog,0,2)
    $pos = FileGetPos($chatlog) ; currently = 141201
_main()

EndFunc

So basicly I want to read a log file that has a lot of lines in it but I cant seem to be able to specify the lines beyond 1808 is this a issue or am i doing somthing wrong ?

I dont want to use Filereadline($chatlog,-1) because the file is "Live" and updates fast and it sometimes misses the odd line, so i want to make sure it reads every line.

any pointers would be appreciated

Thanks in Anticipation!!

Share this post


Link to post
Share on other sites
funkey

You do FileOpen once, but FileClose every time in loop.:mellow:

Edited by funkey

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Share this post


Link to post
Share on other sites
PostHistory

You do FileOpen once, but FileClose every time in loop.:mellow:

i thought by assigning a the var $chatlog = Fileopen("C:\chat.log") as a global would work so each time $chatlog is called the file is opened no ?

any how did quick test

#include <GuiConstantsEx.au3>
#include <File.au3>
#include <Constants.au3>
#include <Misc.au3>

Global  $pos


_start()

Func _main()
While 1
$chatlog = FileOpen("C:\chat.log",0)
$read = FileReadLine($chatlog,$pos)
ConsoleWrite($chatlog&@CR)
ConsoleWrite($read&@CR)
if stringlen($read) > 1 Then
ConsoleWrite($read&@cr)
$pos += 1
EndIf
ConsoleWrite($pos&@cr)
FileClose($chatlog)
WEnd

EndFunc

Func _start()
    $chatlog = FileOpen("C:\chat.log",0)
    FileSetPos($chatlog,0,2)
    $pos = FileGetPos($chatlog) ; currently = 141201
_main()

EndFunc

same issue.

Share this post


Link to post
Share on other sites
enaiman

Quote from help file about FileReadLine:

If a filename is given rather than a file handle - the file will be opened and closed during the function call

If you want to go "FileReadLine" way - you don't need to open/close the file everytime. Be warned - FileReadLine, because of FileOpen and FileClose is SLOW.

You would be better by reading the whole file (_FileReadToArray) then go to the specified index. The increase in performance will be dramatic for big files.


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites
PostHistory

Quote from help file about FileReadLine:

If you want to go "FileReadLine" way - you don't need to open/close the file everytime. Be warned - FileReadLine, because of FileOpen and FileClose is SLOW.

You would be better by reading the whole file (_FileReadToArray) then go to the specified index. The increase in performance will be dramatic for big files.

Will try the _FileReadToArray tonight

did this just now and still no result?

#include <GuiConstantsEx.au3>
#include <File.au3>
#include <Constants.au3>
#include <Misc.au3>

Global  $pos


_start()

Func _main()
While 1
;~ $chatlog = FileOpen("C:\chat.log",0)
$read = FileReadLine("C:\chat.log",$pos)
ConsoleWrite($read&@CR)
if stringlen($read) > 1 Then
ConsoleWrite($read&@cr)
$pos += 1
EndIf
ConsoleWrite($pos&@cr)
WEnd

EndFunc

Func _start()
    $chatlog = FileOpen("C:\chat.log",0)
    FileSetPos($chatlog,0,2)
    $pos = FileGetPos($chatlog)
_main()

EndFunc

Share this post


Link to post
Share on other sites
BrewManNH

Try this way also.

Func _main()
    $chatlog = FileOpen("wordlist.txt", 0)
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $chatlog = ' & $chatlog & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
    While 1
        $read = FileReadLine($chatlog)
        ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $read = ' & $read & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
        If @error = -1 Then ExitLoop
        $pos += 1
        ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $pos = ' & $pos & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
    WEnd
    FileClose($chatlog)
EndFunc   ;==>_main

;
Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
enaiman

Why this FileGetPos? And why going so complicated?

It is as easy as this:

#Include <File.au3>
#Include <Array.au3>

Global $read

_FileReadToArray("C:\chat.log", $read)
_ArrayDisplay($read)

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites
kylomas

PostHistory,

I dont want to use Filereadline($chatlog,-1) because the file is "Live" and updates fast and it sometimes misses the odd line, so i want to make sure it reads every line.

This is a matter of data currency...when you execute the fileopen, explicitly, or implicitly (through readline) then you have every available record. You will not have records written subsequent to the open...

Something like the following reads the entire file to a 0 based array (similar to _filereadtoarray)

Local $mst = StringSplit(FileRead($mstfl_name), @CRLF, 3)

This results in array variable $mst containing the entire file pointed to by $mstfl_name (see the doc to parameter details).

Hope this helps

Kylomas


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

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.