Sign in to follow this  
Followers 0
DeFactos

Reading a file

7 posts in this topic

Hey,

I have a log file that I need to read continually and get the last line from it (to be precise a part of the line so if anyone has any ideas it would be great.

Thanks in advance.

Share this post


Link to post
Share on other sites



This would work:

While 1
    $File = FileOpen("Path to File")            ;Open the file
    $Line = FileReadLine($File,-1)              ;-1 reads the last line of the file
    ;Your Line variable now has the contents of the current last line of the file
    FileClose($File)                            ;Close the file to allow writing by other programs
    Sleep(250)                                  ;Sleep 250 milliseconds to allow fresh write to the log file
WEnd

You'll want to set a hotkey to stop/pause the program

What are you wanting to do with the line once you have it?

-Fett


[sub]My UDF[/sub][sub] - Basics and Time extensions. Great for those new at AutoIt, also contains some powerful time extensions for pros.[/sub][sub]ScrabbleIt[/sub][sub] - Scrabble done in pure AutoIt. (In Progress)[/sub][sub]Nerd Party Extreme | My Portfolio | [email="fett8802@gmail.com"]Contact Me[/email][/sub]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I want to analyse it ( to find a partial match so if the line is 'Hey everyone you rock.' I want to check if it contains 'everyone'. ) And thanks I think that would work but don't have time to check it right now. :)

Edit1:

O.o I forgot to wright a curucial part of my request it doesn't have an extension :). Sorry for this but I thought I have written it.

Edit2:

It opens with notpad.

Edited by DeFactos

Share this post


Link to post
Share on other sites

Sorry for bumping but does anyone else have ideas???

Share this post


Link to post
Share on other sites

Thanks this should work great.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

i whas bored, press esc to abort script

HotKeySet('{ESC}', '_exit')
While 1
    $File = FileOpen("Path to File") ;Open the file
    $Line = FileReadLine($File, -1) ;-1 reads the last line of the file
    FileClose($File) ;Close the file to allow writing by other programs
    If StringInStr($Line, 'everyone') <> 0 Then ExitLoop ; if string contains everyone then exitloop and make coffee
    Sleep(250) ;Sleep 250 milliseconds to allow fresh write to the log file
WEnd
MsgBox(64, 'String found', 'now lets make coffee')

Func _exit()
    Exit
EndFunc   ;==>_exit
Edited by Djarlo

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  
Followers 0