sujithmd
asked on
Files comparing script not working properly
Hello Scriting gurus .. I've created a vb script (.hta) to compare two files the script intended was like below
1) One text to box (A)to give a list of files (.txt)in each line like (A1,A2,A3)
2) Another text box (B) to give a list of files (.txt)in each line like (B1,B2,B3)
when i run the script it should compare A1 file with B1 file and list the matching line as ok and non matching line as not ok.
so what is the problem now ? so far script is satisfying few but not all. the problems are listed below.
1) Say I've given few files A1,A2,A3 and first text box and B1,B2,B3 in second text box it will skip first two files and compare only the last ie A3 and B3 only.
2) And if A3 is comparing with a file in B3 and if the B3 files is having blank lines it says Ok that should not be
Files are giving by their unc paths like E:\A1.txt etc any thoughts and if you need more info i can provide that as well.
<head>
<title>Read the Error Lines of a Log File</title>
<HTA:APPLICATION
APPLICATIONNAME="Read the Error Lines of a Log"
SCROLL="yes"
SINGLEINSTANCE="yes"
>
</head>
<script language="VBScript">
Sub GetProcesses
On Error Resume Next
strHTML = "<table border='1' style='border-collapse: collapse' " & _
"bordercolor='#111111' width='100%' id='Table1' >"
strText = Servers.Value
arrLines = Split(strText, vbCrLf)
For Each strLinee in arrLines
strComputer = strLinee
strText2 = Servers2.Value
arrLines2 = Split(strText2, vbCrLf)
For Each strLinee2 in arrLines2
strcomputer2 = strLinee2
If Len (strComputer) <= 0 Then
strHTML = strHTML & "**Please check the path given**" & "<br>"
Else
strHTML = strHTML & "::::::::::::::::::::::::: :::::::::: :::::::::: ::::::Sear ching for error on " & strComputer & "::::::::::::::::::::::::: :::::::::: :::::::::: ::::::" & "<br>"
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
Set objFile = objFSO.OpenTextFile( strComputer , 1)
Set objFile2 = objFSO.OpenTextFile( strComputer2 , 1)
'strLine = objFile.ReadLine
If Err.Number <> 0 Then
strHTML = strHTML & Err.Description & "<br>"
Else
' strLine2 = objFile2.ReadAll
strHTML = "<table border='1' style='border-collapse: collapse' " & _
"bordercolor='#111111' width='100%' id='Table1' >"
strHTML = strHTML & "<td width='50%'>" & strComputer & "</td>"
strHTML = strHTML & "<td width='8%'>" & "File Name" & "</td>"
strHTML = strHTML & "<td width='50%'>" & strComputer2 & "</td>"
Do Until objFile.AtEndOfStream And objfile2.AtEndOfStream
strLine = objFile.ReadLine
strLine2 = objfile2.ReadLine
IF InStr(strLine, strLine2) <> 0 then
' strHTML = strHTML & InStr(strLine, strLine2) & "<br>"
strHTML = strHTML & "<tr>"
strHTML = strHTML & "<td width='50%'>" & strLine & "</td>"
strHTML = strHTML & "<td width='8%'>" & " OK " & "<br>"
strHTML = strHTML & "<td width='50%'>" & strLine2 & "</td>"
Else
strHTML = strHTML & "<tr>"
strHTML = strHTML & "<td width='50%'>" & strLine & "</td>"
strHTML = strHTML & "<td width='8%'>" & "Not OK" & "</td>"
strHTML = strHTML & "<td width='50%'>" & strLine2 & _
"</td>"
' strHTML = strHTML & strLine &"::::::IS not Matching with :::::::::::: "& strLine2 & "<br>"
'If intResult <> 0 Then
'strHTML = strHTML & strLine & "<br>"
End If
Loop
End If
End If
Next
Next
'objFile.Close
strHTML = strHTML & "</table>"
DataArea.InnerHTML = strHTML
End Sub
</script>
<body>
Please enter the path of the log files you want to check
<textarea name="Servers" id="Servers" rows="10" cols="110"></textarea>
<textarea name="Servers2" id="Servers2" rows="10" cols="110"></textarea>
<input type="button" value="Compare Files" name="run_button" onClick="GetProcesses">
<p>
<span id = "DataArea"></span>
</body>
1) One text to box (A)to give a list of files (.txt)in each line like (A1,A2,A3)
2) Another text box (B) to give a list of files (.txt)in each line like (B1,B2,B3)
when i run the script it should compare A1 file with B1 file and list the matching line as ok and non matching line as not ok.
so what is the problem now ? so far script is satisfying few but not all. the problems are listed below.
1) Say I've given few files A1,A2,A3 and first text box and B1,B2,B3 in second text box it will skip first two files and compare only the last ie A3 and B3 only.
2) And if A3 is comparing with a file in B3 and if the B3 files is having blank lines it says Ok that should not be
Files are giving by their unc paths like E:\A1.txt etc any thoughts and if you need more info i can provide that as well.
<head>
<title>Read the Error Lines of a Log File</title>
<HTA:APPLICATION
APPLICATIONNAME="Read the Error Lines of a Log"
SCROLL="yes"
SINGLEINSTANCE="yes"
>
</head>
<script language="VBScript">
Sub GetProcesses
On Error Resume Next
strHTML = "<table border='1' style='border-collapse: collapse' " & _
"bordercolor='#111111' width='100%' id='Table1' >"
strText = Servers.Value
arrLines = Split(strText, vbCrLf)
For Each strLinee in arrLines
strComputer = strLinee
strText2 = Servers2.Value
arrLines2 = Split(strText2, vbCrLf)
For Each strLinee2 in arrLines2
strcomputer2 = strLinee2
If Len (strComputer) <= 0 Then
strHTML = strHTML & "**Please check the path given**" & "<br>"
Else
strHTML = strHTML & ":::::::::::::::::::::::::
Set objFSO = CreateObject("Scripting.Fi
Set objFile = objFSO.OpenTextFile( strComputer , 1)
Set objFile2 = objFSO.OpenTextFile( strComputer2 , 1)
'strLine = objFile.ReadLine
If Err.Number <> 0 Then
strHTML = strHTML & Err.Description & "<br>"
Else
' strLine2 = objFile2.ReadAll
strHTML = "<table border='1' style='border-collapse: collapse' " & _
"bordercolor='#111111' width='100%' id='Table1' >"
strHTML = strHTML & "<td width='50%'>" & strComputer & "</td>"
strHTML = strHTML & "<td width='8%'>" & "File Name" & "</td>"
strHTML = strHTML & "<td width='50%'>" & strComputer2 & "</td>"
Do Until objFile.AtEndOfStream And objfile2.AtEndOfStream
strLine = objFile.ReadLine
strLine2 = objfile2.ReadLine
IF InStr(strLine, strLine2) <> 0 then
' strHTML = strHTML & InStr(strLine, strLine2) & "<br>"
strHTML = strHTML & "<tr>"
strHTML = strHTML & "<td width='50%'>" & strLine & "</td>"
strHTML = strHTML & "<td width='8%'>" & " OK " & "<br>"
strHTML = strHTML & "<td width='50%'>" & strLine2 & "</td>"
Else
strHTML = strHTML & "<tr>"
strHTML = strHTML & "<td width='50%'>" & strLine & "</td>"
strHTML = strHTML & "<td width='8%'>" & "Not OK" & "</td>"
strHTML = strHTML & "<td width='50%'>" & strLine2 & _
"</td>"
' strHTML = strHTML & strLine &"::::::IS not Matching with :::::::::::: "& strLine2 & "<br>"
'If intResult <> 0 Then
'strHTML = strHTML & strLine & "<br>"
End If
Loop
End If
End If
Next
Next
'objFile.Close
strHTML = strHTML & "</table>"
DataArea.InnerHTML = strHTML
End Sub
</script>
<body>
Please enter the path of the log files you want to check
<textarea name="Servers" id="Servers" rows="10" cols="110"></textarea>
<textarea name="Servers2" id="Servers2" rows="10" cols="110"></textarea>
<input type="button" value="Compare Files" name="run_button" onClick="GetProcesses">
<p>
<span id = "DataArea"></span>
</body>
Hi, it looks like the first problem is due to the script reading the file names separated by a line feed, not a comma. So you should enter
\\server\share\filea.txt
\\server\share\fileb.txt
and not
\\server\share\filea.txt,\ \server\sh are\fileb. txt
For the second issue, replace this:
IF InStr(strLine, strLine2) <> 0 then
with this
If StrComp(strLine, strLine2, vbTextCompare) = 0 Then
Regards,
Rob.
\\server\share\filea.txt
\\server\share\fileb.txt
and not
\\server\share\filea.txt,\
For the second issue, replace this:
IF InStr(strLine, strLine2) <> 0 then
with this
If StrComp(strLine, strLine2, vbTextCompare) = 0 Then
Regards,
Rob.
ASKER
Thanks Rob for the replay the second problem is completely gone now however the first one remains as you mentioned I was giving the files line by line only as you said in your example if give the files in each text box it compares only last two text box ie it will compare fileb1.txt with fileb2.txt also i doubt its just a false reporting or so ? since no errors are shown or is it the result of first file comparison is over written by the last one ? any thoughts ?
\\server\share\filea1.txt
\\server\share\fileb1.txt
\\server\share\filea2.txt
\\server\share\fileb2.txt
\\server\share\filea1.txt
\\server\share\fileb1.txt
\\server\share\filea2.txt
\\server\share\fileb2.txt
Hi, the solution to your second problem was a few logic errors in the way it wrote the output. It was comparing the files, it just wasn't writing the data to the page.
Regards,
Rob.
Regards,
Rob.
<head>
<title>Read the Error Lines of a Log File</title>
<HTA:APPLICATION
APPLICATIONNAME="Read the Error Lines of a Log"
SCROLL="yes"
SINGLEINSTANCE="yes"
>
</head>
<script language="VBScript">
Sub GetProcesses
On Error Resume Next
Err.Clear
strHTML = "<table border='1' style='border-collapse: collapse' " & _
"bordercolor='#111111' width='100%' id='Table1' >"
strText = Servers.Value
arrLines = Split(strText, vbCrLf)
strText2 = Servers2.Value
arrLines2 = Split(strText2, vbCrLf)
For Each strLinee in arrLines
strComputer = strLinee
For Each strLinee2 in arrLines2
strcomputer2 = strLinee2
If Len (strComputer) <= 0 Then
strHTML = strHTML & "**Please check the path given**" & "<br>"
Else
strHTML = strHTML & ":::::::::::::::::::::::::::::::::::::::::::::::::::Searching for error on " & strComputer & ":::::::::::::::::::::::::::::::::::::::::::::::::::" & "<br>"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile( strComputer , 1)
Set objFile2 = objFSO.OpenTextFile( strComputer2 , 1)
'strLine = objFile.ReadLine
If Err.Number <> 0 Then
strHTML = strHTML & Err.Description & "<br>"
Else
' strLine2 = objFile2.ReadAll
strHTML = strHTML & "<table border='1' style='border-collapse: collapse' " & _
"bordercolor='#111111' width='100%' id='Table1' >"
strHTML = strHTML & "<td width='50%'>" & strComputer & "</td>"
strHTML = strHTML & "<td width='8%'>" & "File Name" & "</td>"
strHTML = strHTML & "<td width='50%'>" & strComputer2 & "</td>"
Do Until objFile.AtEndOfStream And objfile2.AtEndOfStream
strLine = objFile.ReadLine
strLine2 = objfile2.ReadLine
If StrComp(strLine, strLine2, vbTextCompare) = 0 Then
'strHTML = strHTML & InStr(strLine, strLine2) & "<br>"
strHTML = strHTML & "<tr>"
strHTML = strHTML & "<td width='50%'>" & strLine & "</td>"
strHTML = strHTML & "<td width='8%'>" & " OK " & "<br>"
strHTML = strHTML & "<td width='50%'>" & strLine2 & "</td>"
Else
strHTML = strHTML & "<tr>"
strHTML = strHTML & "<td width='50%'>" & strLine & "</td>"
strHTML = strHTML & "<td width='8%'>" & "Not OK" & "</td>"
strHTML = strHTML & "<td width='50%'>" & strLine2 & "</td>"
'strHTML = strHTML & strLine &"::::::IS not Matching with :::::::::::: "& strLine2 & "<br>"
'If intResult <> 0 Then strHTML = strHTML & strLine & "<br>"
End If
Loop
End If
objFile.Close
objFile2.Close
End If
strHTML = strHTML & "</table>"
DataArea.InnerHTML = DataArea.InnerHTML & strHTML
Next
Next
'objFile.Close
End Sub
</script>
<body>
Please enter the path of the log files you want to check
<textarea name="Servers" id="Servers" rows="10" cols="110"></textarea>
<textarea name="Servers2" id="Servers2" rows="10" cols="110"></textarea>
<input type="button" value="Compare Files" name="run_button" onClick="GetProcesses">
<p>
<span id = "DataArea"></span>
</body>
ASKER
Thanks Rob for the replay and rework of the code however now its showing more output than the file put for comparison say
Text box A
\\server\share\filea1.txt
\\server\share\fileb1.txt
Text box B
\\server\share\filea2.txt
\\server\share\fileb2.txt
the script is intended to compare the FILE in first line of Text box A with the FILE in first line of Text box B and write the out put and once its done it has to compare the FILE in second line of the Text box A with the File in second line of the Text box B. But now the script is showing more than 4 comparisons instead of two comparisons if I give files as in the above example any ideas ?
Text box A
\\server\share\filea1.txt
\\server\share\fileb1.txt
Text box B
\\server\share\filea2.txt
\\server\share\fileb2.txt
the script is intended to compare the FILE in first line of Text box A with the FILE in first line of Text box B and write the out put and once its done it has to compare the FILE in second line of the Text box A with the File in second line of the Text box B. But now the script is showing more than 4 comparisons instead of two comparisons if I give files as in the above example any ideas ?
Yes, that's happening because it's written to compare the following:
FileA1.txt with FileA2.txt
FileA1.txt with FileB2.txt
FileB1.txt with FileA2.txt
FileB1.txt with FileB2.txt
so it compares each in the first text box with each in the second.
Let me rework it so that it does
FileA1.txt with FileA2.txt
FileA2.txt with FileB2.txt
Rob.
FileA1.txt with FileA2.txt
FileA1.txt with FileB2.txt
FileB1.txt with FileA2.txt
FileB1.txt with FileB2.txt
so it compares each in the first text box with each in the second.
Let me rework it so that it does
FileA1.txt with FileA2.txt
FileA2.txt with FileB2.txt
Rob.
Hi, this should work.
Regards,
Rob.
Regards,
Rob.
<head>
<title>Read the Error Lines of a Log File</title>
<HTA:APPLICATION
APPLICATIONNAME="Read the Error Lines of a Log"
SCROLL="yes"
SINGLEINSTANCE="yes"
>
</head>
<script language="VBScript">
Sub GetProcesses
DataArea.InnerHTML = ""
On Error Resume Next
Err.Clear
strHTML = "<table border='1' style='border-collapse: collapse' " & _
"bordercolor='#111111' width='100%' id='Table1' >"
strText = Servers.Value
arrLines = Split(strText, vbCrLf)
strText2 = Servers2.Value
arrLines2 = Split(strText2, vbCrLf)
If UBound(arrLines) < UBound(arrLines2) Then
intFilesToCompare = UBound(arrLines)
MsgBox "Text box 1 has less files than Text box 2. Only " & intFilesToCompare + 1 & " file(s) will be compared."
ElseIf UBound(arrLines) > UBound(arrLines2) Then
intFilesToCompare = UBound(arrLines2)
MsgBox "Text box 2 has less files than Text box 1. Only " & intFilesToCompare + 1 & " file(s) will be compared."
Else
intFilesToCompare = UBound(arrLines)
'MsgBox "Text boxes are the same. " & intFilesToCompare + 1 & " file(s) will be compared."
End If
For intLine = 0 To intFilesToCompare
strComputer = arrLines(intLine)
strcomputer2 = arrLines2(intLine)
If Len (strComputer) <= 0 Then
strHTML = strHTML & "**Please check the path given**" & "<br>"
Else
strHTML = strHTML & ":::::::::::::::::::::::::::::::::::::::::::::::::::Searching for error on " & strComputer & ":::::::::::::::::::::::::::::::::::::::::::::::::::" & "<br>"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile( strComputer , 1)
Set objFile2 = objFSO.OpenTextFile( strComputer2 , 1)
'strLine = objFile.ReadLine
If Err.Number <> 0 Then
strHTML = strHTML & Err.Description & "<br>"
Else
' strLine2 = objFile2.ReadAll
strHTML = strHTML & "<table border='1' style='border-collapse: collapse' " & _
"bordercolor='#111111' width='100%' id='Table1' >"
strHTML = strHTML & "<td width='50%'>" & strComputer & "</td>"
strHTML = strHTML & "<td width='8%'>" & "File Name" & "</td>"
strHTML = strHTML & "<td width='50%'>" & strComputer2 & "</td>"
Do Until objFile.AtEndOfStream And objfile2.AtEndOfStream
strLine = objFile.ReadLine
strLine2 = objfile2.ReadLine
If StrComp(strLine, strLine2, vbTextCompare) = 0 Then
'strHTML = strHTML & InStr(strLine, strLine2) & "<br>"
strHTML = strHTML & "<tr>"
strHTML = strHTML & "<td width='50%'>" & strLine & "</td>"
strHTML = strHTML & "<td width='8%'>" & " OK " & "<br>"
strHTML = strHTML & "<td width='50%'>" & strLine2 & "</td>"
Else
strHTML = strHTML & "<tr>"
strHTML = strHTML & "<td width='50%'>" & strLine & "</td>"
strHTML = strHTML & "<td width='8%'>" & "Not OK" & "</td>"
strHTML = strHTML & "<td width='50%'>" & strLine2 & "</td>"
'strHTML = strHTML & strLine &"::::::IS not Matching with :::::::::::: "& strLine2 & "<br>"
'If intResult <> 0 Then strHTML = strHTML & strLine & "<br>"
End If
Loop
End If
objFile.Close
objFile2.Close
End If
strHTML = strHTML & "</table>"
DataArea.InnerHTML = DataArea.InnerHTML & strHTML
Next
'objFile.Close
End Sub
</script>
<body>
Please enter the path of the log files you want to check
<textarea name="Servers" id="Servers" rows="10" cols="110"></textarea>
<textarea name="Servers2" id="Servers2" rows="10" cols="110"></textarea>
<input type="button" value="Compare Files" name="run_button" onClick="GetProcesses">
<p>
<span id = "DataArea"></span>
</body>
ASKER
Thanks Rob I had a detailed run on your latest code I Put four files in each text box.
Text Box A
FileA1.txt
FileA2.txt
FileA3.txt
FileA4.txt
Text Box B
FileB1.txt
FileB2.txt
FileB3.txt
FileB4.txt
what i noticed is the in the fourth run the script gives exactly the required output. Is there any we can suppress the other outputs ? as of now the script is running as below.
1) Compare FileA1 with File FileB1 - Write the output
2) Compare FileA2 with File FileB2 - Write the output here wired starts (it writes the output of fileA1 and FileB1 comparison then writes the output of fileA2 and FileB2 comparison)
3) Compare FileA3 with File FileB3 - It writes the output of fileA1 and FileB1 comparison then writes the output of fileA2 and FileB2 comparison then writes the output of FileA3 and FileB3 comparison.
4) Compare FileA4 with File FileB4 - It writes the output of fileA1 and FileB1 comparison then writes the output of fileA2 and FileB2 comparison then writes the output of FileA3 and FileB3 comparison and finally FileA4 and FileB4 comparison
Text Box A
FileA1.txt
FileA2.txt
FileA3.txt
FileA4.txt
Text Box B
FileB1.txt
FileB2.txt
FileB3.txt
FileB4.txt
what i noticed is the in the fourth run the script gives exactly the required output. Is there any we can suppress the other outputs ? as of now the script is running as below.
1) Compare FileA1 with File FileB1 - Write the output
2) Compare FileA2 with File FileB2 - Write the output here wired starts (it writes the output of fileA1 and FileB1 comparison then writes the output of fileA2 and FileB2 comparison)
3) Compare FileA3 with File FileB3 - It writes the output of fileA1 and FileB1 comparison then writes the output of fileA2 and FileB2 comparison then writes the output of FileA3 and FileB3 comparison.
4) Compare FileA4 with File FileB4 - It writes the output of fileA1 and FileB1 comparison then writes the output of fileA2 and FileB2 comparison then writes the output of FileA3 and FileB3 comparison and finally FileA4 and FileB4 comparison
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks a lot Rob its working as expected and at least 50% of my coding has gone now :-)
No problem. Most of your code is still there, it's just reshuffled a bit, and a loop was removed. Thanks for the grade.
Rob.
Rob.
Have a look at the following free apps that do the same thing.
File and folder compare software
http://www.grigsoft.com/download-windiff.htm
http://kdiff3.sourceforge.net/