Jump to content

Recommended Posts

Posted

I am trying to read the last line of a .txt file everytime a new line gets inserted by another program in the .txt file.

I ve tried this:

#include <File.au3>

$file = FileOpen("test.txt", 0)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

        $lineCount = _FileCountLines("test.txt")
        $line = FileReadLine($file, $lineCount)
        If @error = -1 Then ExitLoop; end of file
        If @error = 1 Then
            MsgBox(0,"error","Cannot read line")
        EndIf       
        MsgBox(0,"LineCount", $lineCount & ' ' & $line)
FileClose($file)

But the output is wrong. The output line is not the last line in the .txt file

thanks in advance

Posted

I am trying to read the last line of a .txt file everytime a new line gets inserted by another program in the .txt file.

I ve tried this:

#include <File.au3>

$file = FileOpen("test.txt", 0)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

        $lineCount = _FileCountLines("test.txt")
        $line = FileReadLine($file, $lineCount)
        If @error = -1 Then ExitLoop; end of file
        If @error = 1 Then
            MsgBox(0,"error","Cannot read line")
        EndIf       
        MsgBox(0,"LineCount", $lineCount & ' ' & $line)
FileClose($file)

But the output is wrong. The output line is not the last line in the .txt file

thanks in advance

Posted

I have messed with the line count command. Does not work most of the time. It is supposed to work for server logs from what I have heard.

good luck

the line number is correct. but the output doesnt match that.

  • Moderators
Posted (edited)

$aSplit = StringSplit(StringStripCR(FileRead('FileLocation.Name')), @LF)
MsgBox(64, 'Last Line', $aSplit[$aSplit[0]])

Edited by SmOke_N

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.

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...