Public Function CompareFiles (FilePath1, FilePath2)
Dim FS, File1, File2
Set FS = CreateObject(“Scripting.FileSystemObject”)
Dim FS, File1, File2
Set FS = CreateObject(“Scripting.FileSystemObject”)
If FS.GetFile(FilePath1).Size <> FS.GetFile(FilePath2).Size Then
CompareFiles = True
Exit Function
End If
Set File1 = FS.GetFile(FilePath1).OpenAsTextStream(1, 0)
Set File2 = FS.GetFile(FilePath2).OpenAsTextStream(1, 0)
CompareFiles = True
Exit Function
End If
Set File1 = FS.GetFile(FilePath1).OpenAsTextStream(1, 0)
Set File2 = FS.GetFile(FilePath2).OpenAsTextStream(1, 0)
CompareFiles = False
Do While File1.AtEndOfStream = False
Str1 = File1.Read(1000)
Str2 = File2.Read(1000)
Do While File1.AtEndOfStream = False
Str1 = File1.Read(1000)
Str2 = File2.Read(1000)
CompareFiles = StrComp(Str1, Str2, 0)
If CompareFiles <> 0 Then
CompareFiles = True
Exit Do
End If
Loop
File1.Close()CompareFiles = True
Exit Do
End If
Loop
File2.Close()
End Function
Return value:
The function returns 0 or False if the two files are identical, otherwise True.
Example:
File1 = “C:\countries\apple1.jpg”
File2 = “C:\countries\apple3.jpg”
File1 = “C:\countries\apple1.jpg”
File2 = “C:\countries\apple3.jpg”
If CompareFiles(File1, File2) = False Then
MsgBox “Files are identical.”
Else
MsgBox “Files are different.”
End If
Source: Mercury Forum’s KB articles
MsgBox “Files are identical.”
Else
MsgBox “Files are different.”
End If
Comments
Compare Two Text Files