This method Compares 2 files and returns true or false.
C#.NET
private bool wc_CompareFiles(string FilePath1, string FilePath2)
{
FileInfo FI1 = new FileInfo(FilePath1);
FileInfo FI2 = new FileInfo(FilePath2);
if (FI1.Length != FI2.Length)
return false;
byte[] Filebytes1 = File.ReadAllBytes(FilePath1);
byte[] Filebytes2 = File.ReadAllBytes(FilePath2);
if (Filebytes1.Length != Filebytes2.Length)
return false;
for (int i = 0; i <= Filebytes2.Length - 1; i++)
{
if (Filebytes1[i] != Filebytes2[i])
return false;
}
return true;
}
VB.NET
Private Function wc_CompareFiles(ByVal FilePath1 As String, ByVal FilePath2 As String) As Boolean Dim FI1 As New FileInfo(FilePath1) Dim FI2 As New FileInfo(FilePath2) If FI1.Length <> FI2.Length Then Return False End If Dim Filebytes1 As Byte() = File.ReadAllBytes(FilePath1) Dim Filebytes2 As Byte() = File.ReadAllBytes(FilePath2) If Filebytes1.Length <> Filebytes2.Length Then Return False End If For i As Integer = 0 To Filebytes2.Length - 1 If Filebytes1(i) <> Filebytes2(i) Then Return False End If Next Return True End Function
Happy Programming!!
Tags: C#.Net, OpenSource, VB.NET