let's say i have a .dat file and .hdr file .... i have to compare both of them .... how can i open both of them at the same time and then compare them ? do you think is it prossible? pls help me?
Printable View
let's say i have a .dat file and .hdr file .... i have to compare both of them .... how can i open both of them at the same time and then compare them ? do you think is it prossible? pls help me?
Are they the same format? You could check the size, which would be quick, but if it's binary on one file, and text on the other, you can't.
You can even use Windows Internal command fc. You should use Shell to execute this command.
The only condition here is that the files should be text files.
This is a quick and dirty FileCompare. It works with text and binary files as well.
Just call it with two valid filenames.
It reads both files consecutively into strings and compares them afterwards.
If you want to do some fancy comparing and keep both files open, the code would look like:Code:Private Function FileComp(File1 As String, File2 As String) As Boolean
Dim s1$, s2$, f%
f = FreeFile
Open File1 For Binary As #f: s1 = Space$(LOF(f)): Get #f, , s1: Close f
Open File2 For Binary As #f: s2 = Space$(LOF(f)): Get #f, , s2: Close f
FreeFile f
FileComp = s1 = s2
End Function
Code:Private Function FileComp2(File1 As String, File2 As String) As Boolean
Dim f1%, f2%
f1 = FreeFile: Open File1 For Binary As #f1
f2 = FreeFile: Open File2 For Binary As #f2
'now both files are open to do your reading and comparing
Close #f2: FreeFile f2
Close #f1: FreeFile f1
End Function
From an old project, fast and efficient, note that you may want to change the buffer size.
Note that this function just tell if the two files are differents. If you want to compare the datas and tells the difference or something, this code would be a good frame to start on:
JeffBCode:Private Function filesAreDuplicate(strFile1 As String, strFile2 As String)
' Open both file and compare them
Const BUFFERSIZE = 10240
Dim file1 As Integer
Dim file2 As Integer
Dim lngRemaining1 As Long
Dim lngRemaining2 As Long
Dim lngRemaining As Long
Dim bolFilesAreDuplicate As Boolean
Dim bolFinish As Boolean
Dim buffer1 As String
Dim buffer2 As String
buffer1 = Space$(BUFFERSIZE)
buffer2 = Space$(BUFFERSIZE)
file1 = FreeFile
Open strFile1 For Binary Access Read As #file1
file2 = FreeFile
Open strFile2 For Binary Access Read As #file2
lngRemaining1 = LOF(file1)
lngRemaining2 = LOF(file2)
If lngRemaining1 <> lngRemaining2 Then
bolFilesAreDuplicate = False
Else
bolFilesAreDuplicate = True
End If
lngRemaining = lngRemaining1
While bolFinish = False And bolFilesAreDuplicate = True And _
EOF(file1) = False And EOF(file2) = False
If lngRemaining < BUFFERSIZE Then
buffer1 = Space$(lngRemaining)
buffer2 = Space$(lngRemaining)
End If
Get #file1, , buffer1
Get #file2, , buffer2
DoEvents
If buffer1 <> buffer2 Then
bolFilesAreDuplicate = False
End If
lngRemaining = lngRemaining - Len(buffer1)
If lngRemaining = 0 Then
bolFinish = True
End If
Wend
filesAreDuplicate = bolFilesAreDuplicate
Close #file2
Close #file1
End Function
thank you... really appreciate it.....