CodeItBetter Programming Another VB Programming Blog

How to Check whether two files are identical

Posted on January 5, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'File/Folder Handling - How to Check whether two files are identical

Option Explicit
 
Private Sub Main()
    Dim IsSame%, whole&, part&, buffer1$, buffer2$, x&, start&
    Open "C:\Temp\File1.exe" For Binary As #1
    Open "C:\Temp\File2.exe" For Binary As #2
    IsSame% = True
    If LOF(1) <> LOF(2) Then
        IsSame% = False
    Else
        whole& = LOF(1) \ 10000 'number of whole 10,000 byte chunks
        part& = LOF(1) Mod 10000 'remaining bytes at end of file
        buffer1$ = String$(10000, 0)
        buffer2$ = String$(10000, 0)
        start& = 1
        For x& = 1 To whole& 'this for-next loop will get 10,000
            Get #1, start&, buffer1$ 'byte chunks at a time.
            Get #2, start&, buffer2$ 'byte chunks at a time.
            If buffer1$ <> buffer2$ Then
                IsSame% = False
                Exit For
            End If
            start& = start& + 10000
        Next
        buffer1$ = String$(part&, 0)
        buffer2$ = String$(part&, 0)
        Get #1, start&, buffer1$ 'get the remaining bytes at the end
        Get #2, start&, buffer2$ 'get the remaining bytes at the end
        If buffer1$ <> buffer2$ Then IsSame% = False
    End If
    Close
    If IsSame% Then
        MsgBox "Files are identical", 64, "Info"
    Else
        MsgBox "Files are NOT identical", 16, "Info"
    End If
End Sub
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.