Sign in to follow this  
Followers 0

Help with FileReadLine

3 posts in this topic

#1 ·  Posted (edited)

Hey guys, this may be a bit of a n00b question but for some odd reason I can't get the help file for AutoIt to work on my system (Vista64 bit), it doesn't seem to want to open, and after searching through the forums and the wiki I can't find much information that explains how FileReadLine works exactly, I've only managed to locate a couple of more complex implementations of it, which seem to use it differently then how I intend, but I digress.

Anyways, what I'm looking to do is to open a log file and search for a specific piece of text within a specific line and doing actions based on that, the problem is my current logic is not triggering (likely due to the if statement's logic being faulty).

Check out the snippit of code below, I cut out just the section where the logic seems to be faulty so this isn't the whole script (the rest is unrelated)

ToolTip("Locate your log file and click open", 0, 0)
$x = FileOpenDialog("Open _Event log file", $logdir, "Text files (*.txt)")
$logfile = $x

Func Make()
If $logfile <> "" Then
$linecount = _FileCountLines($logfile)
If FileReadLine($logfile, $linecount -1) = "a quirk." Then
;do stuff

Basically, I want it to find the text "a quirk." in the log file at the 2nd to last line.... preferably i'm looking to just search for 1 specific keyword (in this case "quirk")... even if it reads the whole line I'm trying to get it to find these "trigger" words so to speak. Originally, I tried doing the following

If FileReadLine($logfile, $linecount -1) = * + "quirk" + * Then

but that threw an error, so I removed the * and changed it to a more literal definition (i.e: in the log file, the line should be "a quirk."), but that still isn't executing the code from my IF statement.

Any help would be much appreciated, sorry again if this is a n00b question, like I said, if I could get help to work I'd probably be able to figure this out on my own. :/

Edited by Zenodice

Share this post

Link to post
Share on other sites

#3 ·  Posted (edited)


could try

If StringInStr(FileReadLine($logfile, $linecount -1),  "quirk") ThenoÝ÷ ÙÈ^?ªê-y8ZK,«!êÞßÛ-ébâÛ¥¶)µérÂÇËhÂäÁéejëh×6$temp = FileReadLine($logfile, $linecount -1);sets temp variable
;Msgbox(0,"Status", "line:"&$temp) DEBUG... Don't Touch
Sleep (1000)
If StringInStr($temp, "mallet") Then

Of course, putting in the msgbox to help me debug helped quite a bit in making sure I was getting the right line (even though I was right originally... it helped me be sure and see how it was receiving the formatting).

Either way the StringInStr was exactly what I needed, thanks for the help :)

Edited by Zenodice

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