Jump to content

Recommended Posts

Posted

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!

Posted

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

Posted

Not tested it - but try this

Set 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

 

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=true

 

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

Posted

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

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



×
×
  • Create New...