Jump to content

File comparison


Recommended Posts

Guys, I'm not looking for the code, but I would appreciate some logic help. I have 2 text files with a computer name on each line. The first text file is the output of all the computers in our OU and the second text file is the output of yesterdays scan. I want to find what computers have been deleted and have been added daily and than output that to a 3rd text file. So here is what I have, but it's failed badly :whistle:

#include <file.au3>

Dim $array1loc = "c:\today.txt"
Dim $array2loc = "c:\yesterday.txt"
Dim $aToday
Dim $aYesterday


If not _FileReadToArray($array1loc, $aToday) Then; Load todays file into array 1
    msgbox(4096, "Error", "Could not load " & $array1loc & " into array")
    Exit
EndIf

If not _FileReadToArray($array2loc, $aYesterday) Then; Load yesterdays file into array 2
    msgbox(4096, "Error", "Could not load " & $array2loc & " into array")
    Exit
EndIf

; Check todays list to see if any new computers were added

$foutput = FileOpen("c:\outp.txt", 1)

for $j = 1 to UBound($aToday) - 1
    for $k = 1 to UBound($aYesterday) - 1
        if $aToday[$j] = $aYesterday[$k] Then
            msgbox(0, "debug", $aToday[$j] & " = " & $aYesterday[$k]);testing
            ExitLoop
        Else; Only time this is true is when the computer does not exist in yesterdays list  <------ NOT!!
            FileWriteLine($foutput, $aToday[$j])
        EndIf
    Next
Next


FileClose($foutput)

As you can see my logic is all wrong and I can't seem to think of away to make it work. The way it is now it created at text file with 300,000 entries. I'm thinking the way it is now it will find all the additions because the computername will not exist in the second array. To find all the deletions I imagine I'm going to have to run the scan the opposite way. I know this isn't the most efficient way :lmao: I have read a few posts that talk about Windiff and such, but I would like to get this completed and than use Task Scheduler to have this run everyday automatically.

What I'm trying to do is see if the first computer name in list 1 is anywhere in list 2. If it is I want to cancel and go onto the second computer name in the first list and start checking the second list again. Keep doing that until I get through all the names in the first list. If the computer doesn't exist on the second list than I want to write that computer to a 3rd text file.

After I check for additions I will reverse it and go down the second list and check to see if any computers have been removed from the first list and output that to the same 3rd text file.

Edited by notta
Link to comment
Share on other sites

Not the most efficient, but works

#include <file.au3>
#include <Array.au3>

Dim $array1loc = "c:\today.txt"
Dim $array2loc = "c:\yesterday.txt"
Dim $aToday
Dim $aYesterday


If not _FileReadToArray($array1loc, $aToday) Then; Load todays file into array 1
    msgbox(4096, "Error", "Could not load " & $array1loc & " into array")
    Exit
EndIf

If not _FileReadToArray($array2loc, $aYesterday) Then; Load yesterdays file into array 2
    msgbox(4096, "Error", "Could not load " & $array2loc & " into array")
    Exit
EndIf

_ArraySort($aToday, 0, 1)
_ArraySort($aYesterday, 0, 1)
$foutput = FileOpen("outp.txt", 1)
FileWriteLine($foutput, @YEAR&'-'&@MON&'-'&@MDAY)
FileWriteLine($foutput, "Removed:")
For $i = 1 to $aYesterday[0]
    $key = _ArrayBinarySearch($aToday, $aYesterday[$i], 1)
    If @error Then FileWriteLine($foutput, $aYesterday[$i])
Next
FileWriteLine($foutput, "Added:")
For $j = 1 to $aToday[0]
    $key = _ArrayBinarySearch($aYesterday, $aToday[$j], 1)
    If @error Then FileWriteLine($foutput, $aToday[$j])
Next
FileClose($foutput)

Can use _ArraySearch and not sort the arrays, if they are small.

Edited by Siao

"be smart, drink your wine"

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