I am trying to make a VBScript that will take a text file and compare it with another.
The comparison is based in that, it will read a word in the first file, and if it finds that word on the second file, it will echo it.
My problem is that it only compares the first word of Track.txt to the other file, instead of going through the list of words I would like to find.
Any help is greatly appreciated.
Underneath is the script. I have two different ones, but they both do the same exact thing.
Track.txt is the list of words I want to find in SoftInv.txt. results.txt is where I am giong to output it.
The comparison is based in that, it will read a word in the first file, and if it finds that word on the second file, it will echo it.
My problem is that it only compares the first word of Track.txt to the other file, instead of going through the list of words I would like to find.
Any help is greatly appreciated.
Underneath is the script. I have two different ones, but they both do the same exact thing.
Track.txt is the list of words I want to find in SoftInv.txt. results.txt is where I am giong to output it.
Code:
Const ForReading = 1, ForWriting = 2
Dim fso, txtFile, txtFile2, strLine1, strLine2, strMatch
Set fso = CreateObject("Scripting.FileSystemObject")
Set txtFile1 = fso.OpenTextFile(".\Track.txt", ForReading)
Set strLine1 = CreateObject("VBScript.RegExp")
Do Until txtFile1.AtEndOfStream
strMatch = False
strLine1.Pattern = txtFile1.Readline
Set txtFile2 = fso.OpenTextFile(".\SoftInv4.txt", ForReading)
Do Until txtFile2.AtEndOfStream
strLine2 = txtFile2.Readline
Set colMatches = strLine1.Execute(strLine2)
If colMatches.Count > 0 Then
For Each strMatch in colMatches
Wscript.Echo strLine2
Next
End If
Loop
f.Close
Code:
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(".\SoftInv4.txt", ForReading)
Set objRegEx = CreateObject("VBScript.RegExp")
Set txtFile1 = objfso.OpenTextFile(".\Track.txt", ForReading)
Do Until txtFile1.AtEndOfStream
objRegEx.Pattern = txtFile1.Readline
Do Until objFile.AtEndOfStream
strSearchString = objFile.ReadLine
Set colMatches = objRegEx.Execute(strSearchString)
If colMatches.Count > 0 Then
For Each strMatch in colMatches
Wscript.Echo strSearchString
Next
End If
Loop
Loop
objFile.Close