Jump to content

FileReadLine


 Share

Recommended Posts

I'm trying to load a file from an ini file. The ini read works, but after that it just freezes. Can someone look at this and tell me what I have wrong?

dim $line, $file, $var

$var = IniRead("C:\bi\backuppaths.ini", "paths", "path1", "NotFound")

;MsgBox(4096, "Result", $var)

FileOpen($var & "Backup0215200002.log", 0)

;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

if StringInStr($line,'backup success') Then MsgBox(4096, "Backup", "Backup Successful")

WEnd

fileclose($var)

Link to comment
Share on other sites

GRRR! Thanks man. Here is a tougher one for you. :) That backup file name actually will change every day the sceduled task runs, although the name will always start with 'backup' in the beginning. I would like to be able to open the newest file with 'backup*.log' and use that one. Any ideas? Would I need an array? (little over my head at the moment)

Link to comment
Share on other sites

I will go along with Valuaters' bug fix and I will pick on the file handle bug. Get the handle and close it. Some more error checking would be nice if you can add.

dim $line, $file, $var

$var = IniRead("C:\bi\backuppaths.ini", "paths", "path1", "NotFound")

;MsgBox(4096, "Result", $var)

$handle_read = FileOpen($var & "\Backup0215200002.log", 0)

;Check if file opened for reading OK

If $handle_read = -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($handle_read)

If @error = -1 Then ExitLoop

if StringInStr($line,'backup success') Then MsgBox(4096, "Backup", "Backup Successful")

WEnd

fileclose($handle_read)

:)

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...