Jump to content

Help with reading a file


Shade
 Share

Recommended Posts

try this

#Include <file.au3>
$path = "C:\whatever.txt"
$file = 0
_FileReadToArray($path , $file) ;loads all lines into $file with $file[0] = number of lines
$lastline = $file[$file[0]-1] ;$file[number of line -1]
$secondtolastline = $file[$file[0]-2] ;$file[number of line -2]
MsgBox(0, "", $lastline $ @CRLF & $secondtolastline)
Edited by smstroble

MUHAHAHAHAHA

Link to comment
Share on other sites

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

$2ndlast = ""
$last = ""

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

; Read in lines of text until the EOF is reached
While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    $last = $line
    $2ndlast = $last
Wend

FileClose($file)

MsgBox(0,0,"Last line: " & $last & "; 2nd Last: " & $2ndlast)

Start here if you are new Valuater's AutoIT 1-2-3Looking for an UDF - Look hereDo you need to do it twice - Autoit

Link to comment
Share on other sites

Actually found a bug in my script :)

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

$2ndlast = ""
$last = ""

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

; Read in lines of text until the EOF is reached
While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    ;Need to switch the below as they are now
    $2ndlast = $last
    $last = $line
Wend

FileClose($file)

MsgBox(0,0,"Last line: " & $last & "; 2nd Last: " & $2ndlast)
Edited by Shevilie

Start here if you are new Valuater's AutoIT 1-2-3Looking for an UDF - Look hereDo you need to do it twice - Autoit

Link to comment
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
 Share

  • Recently Browsing   0 members

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