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

About Chris Gralike

Momenteel ben ik manager van de afdeling business continuity bij de zakelijke IT dienstverlener AMIS Services BV. Sinds 2003 ben ik actief in de ICT branche. Tussen 2003 en nu heb ik verschillende rollen vervuld. In de rollen: systeem- en netwerkbeheer, system engineer, servicemanager en nu practice manager ben ik in contact gekomen met uiteenlopende technologieën, methodologieën, ideeën, oplossingen en innovaties. Een rijke ervaring waarmee ik de klanten van Conclusion en AMIS elke dag probeer te ondersteunen. Mijn credo: 'Altijd opzoek een win-win tussen business en technologie.'

Posted on January 6, 2009, in VBS, Windows Compontents and tagged , , , , , , , . Bookmark the permalink. Leave a comment.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: