Sign in to follow this  
Followers 0
Tigerweld

FileReadLine

4 posts in this topic

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)

Share this post


Link to post
Share on other sites



You are missing $File

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

... also depending on your info

$File = FileOpen($var & "\Backup0215200002.log", 0) ; added a slash "\"

8)


NEWHeader1.png

Share this post


Link to post
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)

Share this post


Link to post
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)

:)

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