Jump to content
Sign in to follow this  
frankpintosr

readfile issues

Recommended Posts

frankpintosr

I am trying to have the script read an existing file, and if it finds the string (status) = 0 then display a msg, if it does not find that string, display another msg. This string is always on the last lane, so if you know a way to look at the last line only, that would be great. I have been searching the whole file. Here's my code. PS, I am a total newbee.

;Variables
$Computername = EnvGet("computername")
$Welcome = 0
;$StorageServers = $CMDLineRaw
$StorageServers = "server"
$logfile = "C:\" & $Computername & ".log"

FileOpen ($logfile,0)

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

While 1
    $line = FileReadLine($logfile)
    If @error = -1 Then ExitLoop
   if StringInStr($line, "(status)") > 0 Then
      $var = StringRight($line, 1)
   EndIf

WEnd

If $var = "0" Then
    MsgBox(0, "Process", "sucessfully captured.", 10)
Else
    MsgBox (0, "Process", "data migration CAN NOT BE CONFIRMED, please check C:\" & $Computername & ".log for errors during the process.")
    EndIf

FileClose($logfile)
Edited by frankpintosr

Share this post


Link to post
Share on other sites
weaponx

Perhaps...

#include <File.au3>

$LastLine = _FileCountLines ( $sFilePath )

FileReadLine($sFilePath, $LastLine)

Edited by weaponx

Share this post


Link to post
Share on other sites
frankpintosr

Thank you, that did the trick with some slight tweaking in other areas of my script.

Thanks a bunch!! :D

Perhaps...

#include <File.au3>

$LastLine = _FileCountLines ( $sFilePath )

FileReadLine($sFilePath, $LastLine)

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.