user505210
user505210

Reputation: 1402

comparing 2 files in vbscript

I have 2 files that I want to see if the contents inside are equal or not .Say one of them is a text file like Sample1.txt and the other one is a different file like main.css how can I compare the two to see if the contents inside are the same.

I was thinking like

Content1 = FSO.OpenTextFile(sample.txt).ReadAll
Content2 = FSO.OpenTextFile(main.css).ReadAll
if(Content1 = Content2) Then


End IF

Is there some better way of doing this.

Thanks

Upvotes: 2

Views: 14525

Answers (1)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200293

If your just interested in whether or not the files are different the easiest way would be shelling out to fc:

Function qq(str)
  qq = Chr(34) & str & Chr(34)
End Function

Function AreDifferent(f1, f2)
  cmd = "%COMSPEC% /c fc /b " & qq(f1) & " " & qq(f2)
  AreDifferent = CBool(CreateObject("WScript.Shell").Run(cmd, 0, True))
End Function

Upvotes: 5

Related Questions