Here goes.....!
I have a file called errors, I want to compare the results of the error file with a larger file called persistant.
I want to read the first line of Errors and see if it's in Persistant
I need to do this for every line of errors.
Basically
Set objFSO = CreateObject("Scripting.FileSystemObject")
set str1=objFSO.OpenTextFile("errors.txt")
Set str2=objFSO.OpenTextFile("persistant.txt")
Do While Not str1.AtEndOfStream
com1=str1.ReadLine
com2=str2.ReadLine
If com1 = com2 then
wscript.echo "Match"
Else
WScript.Echo "Not Match"
end if
Loop
str1.close
str2.close
This doesn't work, but you get the idea!
can someone point me in the right direction please!
Basically you need to have one loop inside another.
So:-
1 open the errors.txt file
2 Get the next (first) errors.txt line
3 Open the persistant.txt file
4 Get the next (first) persistant.txt line
5 Compare the two lines
6 go back to 4 until you reach the end of the persistant.txt file
7 go back to 2 until you reach the end of the errors.txt line
8 Close everything
Basically you are opening the first file, then comparing it to every line in the second file, then getting getting the next line and comparing it to every line in the second file again.
Might take some time if you have large files - and there are probably smarter ways, but this is the easier way to get going.
You have all the elements in your code, you just need to reorder them a bit and stick an extra couple of bits in
Not tested it - but try this
This will flash up everytime it matches or does not match a line - if you want it to just flash once for the file, which I am guessing you do then instead of outputting "Match" when it finds it set a variable like ismatch=trueSet objFSO = CreateObject("Scripting.FileSystemObject")
Set str1 = objFSO.OpenTextFile("c:\errors.txt")
Set str2 = objFSO.OpenTextFile("c:\persistant.txt")
Do While Not str1.atEndOfStream
com1 = str1.ReadLine
Set str2 = objFSO.OpenTextFile("c:\persistant.txt")
Do While Not str2.atEndOfStream
com2 = str2.ReadLine
If com1 = com2 Then
WScript.Echo "Match"
Else
WScript.Echo "Not Match"
End If
Loop
str2.Close
Loop
str1.Close
Then when you get to the end output if ismatch=true then "Match" etc..
Just make sure you set ismatch to be false at the beginning of the code somewhere.
Edit - decided to just do it and add it instead of trying to describe it
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set str1 = objFSO.OpenTextFile("c:\errors.txt")
Set str2 = objFSO.OpenTextFile("c:\persistant.txt")
ismatch = False
Do While Not str1.atEndOfStream
com1 = str1.ReadLine
Set str2 = objFSO.OpenTextFile("c:\persistant.txt")
Do While Not str2.atEndOfStream
com2 = str2.ReadLine
If com1 = com2 Then
ismatch = True
End If
Loop
str2.Close
Loop
str1.Close
If ismatch = True Then
wscript.echo "Match"
Else
wscript.echo "Not Match"
End If
Thanks for that Limbo, it was more of the 1st I was looking for than the 2nd.
A bit of choping and changing and it's sorted thanks, I knew it was the looping that was going awray, just wasn't able to figure out why, so thanks for that!!
We aim to please!
There are currently 1 users browsing this thread. (0 members and 1 guests)