Jump to content

[solved] intermidiant failure of _FileDeleteLine


Prab
 Share

Recommended Posts

Hi,

I am having trouble with the following.

#include <File.au3>
#include <Array.au3>

Opt("TrayAutoPause", 0)

Global $sOnlineFile = "Online.txt"
Global $sOfflineFile = "Offline.txt"
Global $sOutputFile = "Log.txt"
Global $iDelay = 100

While 1
    $sOutput = ""
    $sOutput = $sOutput & CheckOnline()
    $sOutput = $sOutput & CheckOffline()
;If $sOutput <> "" Then Output($sOutput)
    Sleep($iDelay)
WEnd

;_FileDeleteLine("Online.txt", "abc")

Func CheckOnline()
    Local $aRecords
    Local $sToReturn
    If Not _FileReadToArray($sOnlineFile,$aRecords) Then
       Return " Error reading log to Array   error:" & @error
   EndIf
   
    For $x = 1 to $aRecords[0]
        If Ping($aRecords[$x]) = 0 Then
            $sToReturn = $sToReturn & " " & $aRecords[$x] & " went offline" & @CRLF
            FileWriteLine($sOfflineFile, $aRecords[$x])
            MsgBox(0,"","|" & $sOfflineFile & "," & $aRecords[$x] & "|")
            _FileDeleteLine($sOnlineFile, $aRecords[$x])
        EndIf
    Next
    
    _ArrayDelete($aRecords, 0)
    _FileWriteFromArray($sOnlineFile, $aRecords)
    
    Return $sToReturn
EndFunc

Func _FileDeleteLine($sFileName, $sToDelete)
    Local $aRecords
    _FileReadToArray($sFileName, $aRecords)
    Local $File = FileOpen($sFileName, 2)
    For $x = 1 to $aRecords[0]
        If $aRecords[$x] == $sToDelete Then 
        Else
            FileWriteLine($File, $aRecords[$x])
        EndIf
    Next
    FileClose($File)
EndFunc

_FileDeleteLine("Online.txt", "abc") works, but if I have "abc" in the Online.txt file, that line does not get deleted. Any suggestions?

Edited by Prab
Link to comment
Share on other sites

Am I the only one confused?

_FileDeleteLine("Online.txt", "abc") works

and

if I have "abc" in the Online.txt file, that line does not get deleted

looks like a contradiction:

if your function works (1st part is true) then it will delete the record so the 2 nd part is false

if your function doesn't work (1st part false) then the record is not deleted therefore the 2nd part is true

...

What should I understand?

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

I solved this issue. What I meant was if I ran just _FileDeleteLine("Online.txt", "abc") it worked, but if I ran Func CheckOnline() when it called _FileDeleteLine it did not work.

The issue was that _FileDeleteLine worked the whole time but at the end of the function I had FileWriteFromArray($sOnlineFile, $aRecords) which would add back all the lines that I just deleted. Oops.

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