Hello all,

Is there a way I can use WSH to compare two files for equality? Do I
have to call the DOS 'fc' or 'comp' commands?

I was thinking about writing my own comparison function by then I'd
have to be able to read a binary file. Is this possible as well?

Thank you.

--
Tony LaPaso

Re: Using WSH to Copmpare Files by Miyahn

Miyahn
Tue Jul 19 22:28:20 CDT 2005

"Tony LaPaso" wrote in message news:#EVpQ7LjFHA.2156@TK2MSFTNGP14.phx.gbl
> I was thinking about writing my own comparison function by then I'd
> have to be able to read a binary file. Is this possible as well?

Only for this point.
Here is an example to read a binary file.
"Hexadecimal dump tool".

' FileName:HexDump.vbs
Dim Args, aBuf(), bBuf(), sBuf, Size, I, J, J2, K, M, aCode, Head, Tail
Set Args = WScript.Arguments
If Args.Count = 0 Then Reg_UnReg
If Args.Count <> 1 Then WScript.Quit
With CreateObject("Scripting.FileSystemObject")
If Not .FileExists(Args(0)) Then WScript.Quit
End With
Head = "pre" & vbCrLf & _
" 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F" & vbCrLf _
& " -----------------------------------------------" & vbCrLf
Tail = "/pre" & vbCrLf
With CreateObject("ADODB.Stream")
.Mode = 3: .Type = 1: .Open: .LoadFromFile Args(0)
Size = .Size: ReDim aBuf((Size \ 16 + 1) * 32), bBuf(Size)
For I = 1 To .Size: bBuf(I) = .Read(1): Next: .Close
End With
J = 1: K = 0: M = 0: aBuf(0) = Head
For I = 1 To Size
J2 = J + 16: aCode = AscB(bBuf(I))
aBuf(J) = Right("0" & Hex(aCode), 2) & " "
If I Mod 16 = 1 Then aBuf(J) = Right("0" & Hex(K), 2) & _
Hex(M) & "0: " & aBuf(J): M = (M + 1) Mod 16
If aCode > &H1F And aCode < &h7F Then aBuf(J2) = Chr(aCode) _
Else aBuf(J2) = "."
If I Mod 16 = 0 Then
aBuf(J) = aBuf(J) & vbTab: aBuf(J2) = aBuf(J2) & vbCrLf
If I Mod 256 = 0 Then _
aBuf(J2) = aBuf(J2) & Tail & Head: K = K + 1
J = J2
End If
J = J + 1
Next
If J Mod 16 <> 0 Then
For I = J To (J \ 16 + 1) * 16: aBuf(I) = " ": Next
aBuf(I - 1) = aBuf(I - 1) & vbTab
End If
aBuf(UBound(aBuf)) = aBuf(UBound(aBuf)) & vbCrLf & Tail
sBuf = Join(aBuf, "")
With New RegExp
.Global = True: .IgnoreCase = False: .MultiLine = True
sBuf = Replace(Replace(sBuf, "<", "&lt;"), ">", "&gt;")
.Pattern = "^((/)?pre)": sBuf = .Replace(sBuf, "<$1>")
End With
With CreateObject("InternetExplorer.Application")
.Navigate "about:blank"
.document.Write _
"<title>" & Mid(Args(0), InstrRev(Args(0), "\") + 1) & _
"</title></head>" & vbCrLf & CStr(sBuf)
.Visible = True
End With
Sub Reg_UnReg
Const TKey = "HKCR\*\shell\HexDump\", Menu = "HexadecimalDump(&H)"
Dim EN
With CreateObject("WScript.Shell")
On Error Resume Next
.RegRead TKey: EN = Err.Number
On Error GoTo 0
If EN <> 0 Then
.RegWrite Tkey, Menu
.RegWrite Tkey & "command\", _
"wscript """ & WScript.ScriptFullName & """ ""%L"""
.PopUp "Added to context menu.", 1
Else
.RegDelete Tkey & "command\": .RegDelete Tkey
.PopUp "Deleted from context menu.", 1
End If
End With
End Sub

--
Miyahn (Masataka Miyashita) JPN
Microsoft MVP for Microsoft Office - Excel(Jan 2005 - Dec 2005)
HQF03250@nifty.ne.jp


Re: Using WSH to Copmpare Files by D

D
Wed Jul 20 04:04:11 CDT 2005

You could try a shareware tool called "Duplic8" ;
http://www.kewlit.com/duplic8/

I have a script that uses "FC" command line tool, but my script is a bit big
and might be a bit complicated for a newbie. Would you like me to post a
copy?



Re: Using WSH to Copmpare Files by Michael

Michael
Thu Jul 21 19:29:50 CDT 2005

Tony LaPaso wrote:
> Hello all,
>
> Is there a way I can use WSH to compare two files for equality? Do I
> have to call the DOS 'fc' or 'comp' commands?
>
> I was thinking about writing my own comparison function by then I'd
> have to be able to read a binary file. Is this possible as well?
>

Perform Binary Compare Of Two Files
http://cwashington.netreach.net/depo/view.asp?Index=492&ScriptType=component

--
Michael Harris
Microsoft MVP Scripting





Re: Using WSH to Copmpare Files by Tony

Tony
Thu Jul 21 20:38:02 CDT 2005

Well,

Here's how I did it -- it turns out it's not so bad to use fc:

var ret = shell.Run("fc /b " + DATA_FILE + " temp.mny >nul", 0, true);
var shell = WScript.CreateObject("WScript.Shell");
if(ret == 0) {
//... Files are equal
}




--
Tony LaPaso
"Tony LaPaso" <tlapaso@comcast.net> wrote in message
news:%23EVpQ7LjFHA.2156@TK2MSFTNGP14.phx.gbl...
> Hello all,
>
> Is there a way I can use WSH to compare two files for equality? Do I
> have to call the DOS 'fc' or 'comp' commands?
>
> I was thinking about writing my own comparison function by then I'd
> have to be able to read a binary file. Is this possible as well?
>
> Thank you.
>
> --
> Tony LaPaso
>



Re: Using WSH to Copmpare Files by Paul

Paul
Thu Jul 21 21:57:33 CDT 2005

Comparing files byte by byte can be slow.

If two files have the same size and CRC32 checksum, they are very likely
identical.
I personally like a freeware crc32 COM object called COMCRC, available at
http://www.geocities.com/SiliconValley/Vista/1388/. It is a long page and
there are a number of CRC-related items. This COM object is fairly fast and
handles DVD-sized files easily. A sneaky person can modify a file in a way
that the size and CRC32 checksum is unchanged.

It is almost impossible to modify a file such that its MD5 checksum is
unchanged. I have not yet found a MD5 checksum COM object. I have found
one handy MD5 program which can be put in a folder and which produces a list
of MD5 checksums on all the files in the folder and its subfolder. It can
also validate all the files against that list. Prior to creating a CD with
data such as digital pictures, I create a folder of everything I intend to
put on the CD, put this program in the folder, and run it to create the
list. After creating the CD, I run the program on the CD and it reads the
CD and verifies all the files on the CD. Look for dvdsig at
http://members.ozemail.com.au/~nulifetv/freezip/freeware/

If I want to compare two folders, I run dvdsig on each of them, DOS sort the
resulting .MD5 files, and then run DOS file compare to spot any differences.

-Paul Randall

"Tony LaPaso" <tlapaso@comcast.net> wrote in message
news:#EVpQ7LjFHA.2156@TK2MSFTNGP14.phx.gbl...
> Hello all,
>
> Is there a way I can use WSH to compare two files for equality? Do I
> have to call the DOS 'fc' or 'comp' commands?
>
> I was thinking about writing my own comparison function by then I'd
> have to be able to read a binary file. Is this possible as well?
>
> Thank you.
>
> --
> Tony LaPaso
>
>