'التابع
Public Function CompareFiles(ByVal File1 As String, _
ByVal File2 As String) As Boolean
' Compares contents of two files, byte by byte
' and returns true if no differences
Dim blnIdentical As Boolean = True
Dim objFS1 As System.IO.FileStream = _
New System.IO.FileStream(File1, System.IO.FileMode.Open)
Dim objFS2 As System.IO.FileStream = _
New System.IO.FileStream(File2, System.IO.FileMode.Open)
' Begin by checking length
If (objFS1.Length <> objFS2.Length) Then
blnIdentical = False
Else
' Start looping through, comparing bytes
Dim intByteF1 As Integer
Dim intByteF2 As Integer
Do
intByteF1 = objFS1.ReadByte()
intByteF2 = objFS2.ReadByte()
If intByteF1 <> intByteF2 Then
blnIdentical = False
Exit Do
End If
Loop While (intByteF1 <> -1)
End If
' Close files and set return value
objFS1.Close()
objFS2.Close()
Return blnIdentical
End Function
'في أي مكان
If CompareFiles("c:\1.txt", "c:\2.doc") Then
MessageBox.Show("Files are identical!")
Else
MessageBox.Show("Files do not match!")
End If
Public Function CompareFiles(ByVal File1 As String, _
ByVal File2 As String) As Boolean
' Compares contents of two files, byte by byte
' and returns true if no differences
Dim blnIdentical As Boolean = True
Dim objFS1 As System.IO.FileStream = _
New System.IO.FileStream(File1, System.IO.FileMode.Open)
Dim objFS2 As System.IO.FileStream = _
New System.IO.FileStream(File2, System.IO.FileMode.Open)
' Begin by checking length
If (objFS1.Length <> objFS2.Length) Then
blnIdentical = False
Else
' Start looping through, comparing bytes
Dim intByteF1 As Integer
Dim intByteF2 As Integer
Do
intByteF1 = objFS1.ReadByte()
intByteF2 = objFS2.ReadByte()
If intByteF1 <> intByteF2 Then
blnIdentical = False
Exit Do
End If
Loop While (intByteF1 <> -1)
End If
' Close files and set return value
objFS1.Close()
objFS2.Close()
Return blnIdentical
End Function
'في أي مكان
If CompareFiles("c:\1.txt", "c:\2.doc") Then
MessageBox.Show("Files are identical!")
Else
MessageBox.Show("Files do not match!")
End If
تعليقات
إرسال تعليق