Jump to content

compare txt file contents


Recommended Posts

How would i read all of the contents of a .log file and if the window that pops up matches the name of a line from the .txt it closes

like...

if winexists(".txt file contents") Then
          WinKill("^that")

[right][font="Courier New"]...Run these streets all day, I can sleep when I die.[/font] [/right]

Link to comment
Share on other sites

Fronzeyam has done a slight mistake in his code....I'll correct that and tell you what you need to do....I imagine you want to do a popup blocker?Lets assume that your log file is called "popup.txt" and is located in C:\....

$file=FileOpen("C:\popup.txt",0)
$NumLine = _FileCountLines($file)

While 1

       For $CountLines = 0 To $NumLine
               $LineRead = FileReadLine ($file, $CountLines)
               If WinExists($LineRead) Then WinKill($LineRead)
        Next

Wend

As you can see While 1 is an endless loop that checks For popup Windows all the time....It checks every line it reads if there is a window with that name and if true ,it will kill it....Of course endless loop is an option and you could call it whenever you like through a HotKey or at set intervals with Sleep()....

C ya

Link to comment
Share on other sites

It Dosent seem 2 be working..maybe i worded it rong???

#include <GuiConstants.au3>
#include <file.au3>
GuiCreate("Insert Title Here",400,300)
$aba = GuiCtrlCreateButton("test",0,130,50,25)
GuiSetState()
While 1
      $msg = GuiGetMsg()
             If $msg = $GUI_EVENT_CLOSE Then ExitLoop           
            Select
            Case $msg = $aba 
                $file = FileOpen("C:\blocklist1.log",0)
                $NumLine = _FileCountLines($file)
            
        For $countLines = 0 To $NumLine
            $LineRead = FileReadLine($file,$CountLines)
            If WinExists($LineRead) Then WinKill($LineRead)
            EndSelect
WEnd
FileClose($file)

contents of C:\blocklist1.log:

C:\

My Computer

Mozilla Firefox

Edited by B3TA_SCR1PT3R

[right][font="Courier New"]...Run these streets all day, I can sleep when I die.[/font] [/right]

Link to comment
Share on other sites

#include <GuiConstants.au3>
#include <file.au3>
GuiCreate("Insert Title Here",400,300)
$aba = GuiCtrlCreateButton("test",0,130,50,25)
GuiSetState()
While 1
    $msg = GuiGetMsg()
        
    Select
        Case $msg = $GUI_EVENT_CLOSE 
            ExitLoop 
        Case $msg = $aba 
            $file = FileOpen("C:\blocklist1.log",0)
            $NumLine = _FileCountLines($file)
            
            For $countLines = 0 To $NumLine
                $LineRead = FileReadLine($file,$CountLines)
                If WinExists($LineRead) Then WinKill($LineRead)
            Next
        FileClose($file)    
    EndSelect
WEnd

not tested

8)

NEWHeader1.png

Link to comment
Share on other sites

tested and works... same problem "_filecountlines" returns 0

#include <GuiConstants.au3>
#include <file.au3>
GuiCreate("Insert Title Here",400,300)
$aba = GuiCtrlCreateButton("test",0,130,50,25)
GuiSetState()
While 1
    $msg = GuiGetMsg()
        
    Select
        Case $msg = $GUI_EVENT_CLOSE 
            ExitLoop 
        Case $msg = $aba 
            $file = FileOpen("C:\blocklist1.txt",0); note "txt"
            If $file = -1 Then  
                MsgBox(0, "Error", "Unable to open file.")
                Exit
            EndIf
            
            For $x = 1 To 1000
                $LineRead = FileReadLine($file,$x)
                If @error = -1 Then ExitLoop
                MsgBox(0, "Test Box", "looking for " & $Lineread & "  " & @CRLF & " Line number " & $x ); for testing
                If WinExists($LineRead) Then WinKill($LineRead)
            Next
            
    EndSelect
WEnd
FileClose($file)

8)

NEWHeader1.png

Link to comment
Share on other sites

#Include <GuiConstants.au3>
#Include <_CountLines.au3>

Global $NumLine
$File = FileOpen("C:\blocklist1.txt",0)
$Lines = _CountLines($File)

GuiCreate("Insert Title Here",400,300)
   $Test = GuiCtrlCreateButton("Test",0,130,50,25)

GuiSetState()

While 1
   $Msg = GuiGetMsg()
   Select
      Case $Msg = $GUI_EVENT_CLOSE         
    ExitLoop
   EndSelect
            
   For $countLines = 0 To $Lines
   $LineRead = FileReadLine($file, $Lines)
      If WinExists($LineRead) Then WinKill($LineRead)
   Next
WEnd

FileClose ("C:\blocklist1.txt")

There that should work as long as you download the count lines program from the attachment to this reply. I had to write my own because the one that the other guy wrote doesn't work. Let me know how this go.

:whistle:

_CountLines.au3

"... and the Lord said to John, "Come forth and ye shall receive eternal life," but instead John came fifth and won a toaster."

Link to comment
Share on other sites

#include <file.au3>
Opt("WinTitleMatchMode", 2)

Dim $filename = "C:\popup.txt", $filesize[2], $filecont[1]


While 1
    $filesize[0] = FileGetSize( $filename)
    If $filesize[0] <> $filesize[1] Then
        $filesize[1] = $filesize[0]
        _FileReadToArray( $filename, $filecont)
;~      ToolTip( $filesize[0] & " - " & $filesize[1], 0, 0)
    EndIf
    
    For $i = 1 To $filecont[0]
        If $filecont[$i] <> "" Then
        WinKill( $filecont[$i])
        EndIf
        Sleep( 1)
    Next
    
    Sleep( 50)
WEnd

14623_test.au3

Link to comment
Share on other sites

maybe something like this would work?

Global $BigArseString
$input = fileopen("C:\log.log",0)
while 1
    $line = FileReadLine($input)
    if $line = -1 then ExitLoop
    $BigArseString = $BigArseString & $line
WEnd
while 1
$ListOWins = WinList()
for $x = 1 to $ListOWins[0][0]
    if StringInStr($BigArseString,$ListOWins[$x][0]) Then
        WinClose($ListOWins[$x][0])
    EndIf
Next
sleep(1000)
WEnd

***edit*** forgot to say that i just whipped that up to meet concept requested, haven't tested, and i have it set to check log file only once and check open windows only every second at most... both of those would be easily modified if necessary...

Edited by cameronsdad
Link to comment
Share on other sites

maybe something like this would work?

Global $BigArseString
$input = fileopen("C:\log.log",0)
while 1
    $line = FileReadLine($input)
    if $line = -1 then ExitLoop
    $BigArseString = $BigArseString & $line
WEnd
while 1
$ListOWins = WinList()
for $x = 1 to $ListOWins[0][0]
    if StringInStr($BigArseString,$ListOWins[$x][0]) Then
        WinClose($ListOWins[$x][0])
    EndIf
Next
sleep(1000)
WEnd

***edit*** forgot to say that i just whipped that up to meet concept requested, haven't tested, and i have it set to check log file only once and check open windows only every second at most... both of those would be easily modified if necessary...

<{POST_SNAPBACK}>

I've got to say that I love the name of your Global variable "BigArseString." I'm not sure as there has been no reply from the person in the longest time, but me thinks he chose one of the current ones and used it. Always nice to have alternatives I guess though. :whistle:

"... and the Lord said to John, "Come forth and ye shall receive eternal life," but instead John came fifth and won a toaster."

Link to comment
Share on other sites

I've got to say that I love the name of your Global variable "BigArseString." I'm not sure as there has been no reply from the person in the longest time, but me thinks he chose one of the current ones and used it. Always nice to have alternatives I guess though.  :whistle:

<{POST_SNAPBACK}>

yep, choices = good. wanted to say i like your sig, actually laughed out loud at that (not like one of those annoying 'laughing so loud people ask me what i'm laugh at' things, but there was an audible chuckle...
Link to comment
Share on other sites

yep, choices = good.  wanted to say i like your sig, actually laughed out loud at that (not like one of those annoying 'laughing so loud people ask me what i'm laugh at' things, but there was an audible chuckle...

<{POST_SNAPBACK}>

Thanks

I like your binary "BADCODED" too :whistle:

"... and the Lord said to John, "Come forth and ye shall receive eternal life," but instead John came fifth and won a toaster."

Link to comment
Share on other sites

Actually i have never tested the _FileCountLines UDF and didnt know it would be problematic....Otherwise the code was right...Although i didnt have to use For...Next but While 1 and the If @error=-1 statement to check for the EOF....But i was inspired by frozeyam's code(BTW where is his first post?!?).I was more anxious with anomalies in WinTitleMatchMode rather than the rest of the code....

I'm glad you got it working now...

C ya

EDIT:Typos

Edited by hgeras
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...