منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب
للمقارنة بين ملفين - نسخة قابلة للطباعة

+- منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب (http://vb4arb.com/vb)
+-- قسم : الأقسام التعليمية - المنتدى القديم (http://vb4arb.com/vb/forumdisplay.php?fid=90)
+--- قسم : مكتبة أكواد المنتدى (http://vb4arb.com/vb/forumdisplay.php?fid=111)
+---- قسم : مكتبة أكواد .net (http://vb4arb.com/vb/forumdisplay.php?fid=117)
+---- الموضوع : للمقارنة بين ملفين (/showthread.php?tid=6198)



للمقارنة بين ملفين - RaggiTech - 17-10-12

كاتب الموضوع : AhmedEssawy


كود :
' ----------------------------------------
' Required Imports :
'
' System.IO
' ----------------------------------------
Private Function CompareFiles(ByVal file1 As String, ByVal file2 As String) As Boolean
'Set to true if the files are equal; false otherwise
Dim filesAreEqual As Boolean = False
With My.Computer.FileSystem
' Ensure that the files are the same length before comparing them line by line
If .GetFileInfo(file1).Length = .GetFileInfo(file2).Length Then
Using file1Reader As New FileStream(file1, FileMode.Open), _
file2Reader As New FileStream(file2, FileMode.Open)
Dim byte1 As Integer = file1Reader.ReadByte()
Dim byte2 As Integer = file2Reader.ReadByte()
' If byte1 or byte2 is a negative value, we have reached the end of the file
While byte1 > 0 And byte2 > 0
If (byte1 <> byte2) Then
filesAreEqual = False
Exit While
Else
filesAreEqual = True
End If
'Read the next byte
byte1 = file1Reader.ReadByte()
byte2 = file2Reader.ReadByte()
End While
End Using
End If
End With
Return filesAreEqual
End Function