Link to home
Start Free TrialLog in
Avatar of GlobaLevel
GlobaLevelFlag for United States of America

asked on

Vbscript - want ot compare 2 .txt line by line in a folder and output diferrences

hi see attached i am trying to compare 2 txt in a folder and output the differences to msgbox can t get it to work... help!
Set objArgs = Wscript.Arguments
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile1 = objFSO.GetFile(objArgs(0))
Set objFile2 = objFSO.GetFile(objArgs(1))
Set FileStream1 = objFSO.OpenTextFile(objFile1.C:\_Transfer\NWP\compare2 files\APICustomer1022-jeffs.txt)
Set FileStream2 = objFSO.OpenTextFile(objFile2.C:\_Transfer\NWP\compare2 files\APICustomer1022-russloaded.txt)
While (Not FileStream1.AtEndOfStream) Or (Not FileStream2.AtEndOfStream)
    if Not FileStream1.AtEndOfStream Then
        sLine1 = FileStream1.ReadLine()
    Else
        sLine1 = ""
    End If
    If Not FileStream2.AtEndOfStream Then
        sLine2 = FileStream2.ReadLine()
    Else
        sLine2 = ""
    End If
    If sLine1 <> sLine2 Then
        sAllLines =  sAllLines & sLine1 & chr(10) & chr(13) & sLine2 & chr(10) & chr(13) 
    End If
Wend
if sAllLines <> "" Then
    Wscript.Echo sAllLines 
End if
)

Open in new window

I-have-my-2-files-in-this-folder.docx
ASKER CERTIFIED SOLUTION
Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Also, not sure why you have the ")" on Line25
GlobaLevel,

Beg your pardon, I didn't save before uploading!

Called, (restructured to use your file refs) as:
myfile.vbs "C:\_Transfer\NWP\compare2 files\APICustomer1022-jeffs.txt" "C:\_Transfer\NWP\compare2 files\APICustomer1022-russloaded.txt"

chris_bottomley
Set objArgs = Wscript.Arguments
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Set objFile1 = objFSO.GetFile(objArgs(0))
'Set objFile2 = objFSO.GetFile(objArgs(1))
'Set FileStream1 = objFSO.OpenTextFile(objFile1.C:\_Transfer\NWP\compare2 files\APICustomer1022-jeffs.txt)
'Set FileStream2 = objFSO.OpenTextFile(objFile2.C:\_Transfer\NWP\compare2 files\APICustomer1022-russloaded.txt)
Set FileStream1 = objFSO.OpenTextFile(objArgs(0))
Set FileStream2 = objFSO.OpenTextFile(objArgs(1))
While (Not FileStream1.AtEndOfStream) Or (Not FileStream2.AtEndOfStream)
    if Not FileStream1.AtEndOfStream Then
        sLine1 = FileStream1.ReadLine()
    Else
        sLine1 = ""
    End If
    If Not FileStream2.AtEndOfStream Then
        sLine2 = FileStream2.ReadLine()
    Else
        sLine2 = ""
    End If
    If sLine1 <> sLine2 Then
        sAllLines =  sAllLines & sLine1 & chr(10) & chr(13) & sLine2 & chr(10) & chr(13) 
    End If
Wend
if sAllLines <> "" Then
    Wscript.Echo sAllLines 
End if 
filestream1.close
filestream2.close

Open in new window

@Chris_Bottomley - Your script is correct if he wants to use the Arguments as in his original instead of the hard-coded paths.  He had both in his original, hehe, you took the Argument approach and I took the hard-coded approach.  Both was in his original.  That is toooo funny :)