Compare File contence using VBScript.

Ever had the need to compare a file using VBS? You might wonder why you might need something like that? For instance. You have all your coperate templates on your network, but you want to upload these to your portable clients so they always have access to these templates. To keep these clients up-to-date you only want to upload these template each time a version file is changed on the network.

To do this you need to compare the contence of that file. Here is a script that will enable you to do just that.

Set Fso = WScript.CreateObject(“Scripting.FileSystemObject”)

CopyTemplates = “NotSet”
If Fso.FileExists(“C:\office\version.txt”) then
set objFile1 = Fso.opentextfile(“C:\AMIS-Huisstijl\office\versie.txt”,1)
CopyTemplates = “True”
End If
If Fso.FileExists(“F:\office\version.txt”) then
set objFile2 = Fso.opentextfile(“F:\AMIS-Huisstijl\office\versie.txt”,1)
CopyTemplates = “True”
End If
If CopyTemplates = “NotSet” Then
arrFile1 = split(objFile1.ReadAll,vbNewLine)
arrFile2 = split(objFile2.ReadAll,vbNewLine)
If ubound(arrFile1) ubound(arrFile2) then
intLineCount = ubound(arrFile2)
strError = strFile2 & ” is bigger than ” & strFile1
intLineCount = ubound(arrFile2)
End if
for i = 0 to intLineCount
if not arrFile1(i) = arrFile2(i) then
exit for
end if
If i < (intLineCount + 1) then
CopyTemplates = “True”
Elseif strError “” then
CopyTemplates = “True”
CopyTemplates = “False”
End If
WScript.Echo “Copy Templates = ” & CopyTemplates
End If


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s