I need to compare one file in each file in the folders, some sort of duplicate check through md5 hashcode that I've found in my google search.
Here's the code of functions:
Public Function CompareFiles(ByVal FirstFile As String, _ ByVal SecondFile As String) As Boolean Return ReadFile(FirstFile) = ReadFile(SecondFile) End Function Private Function ReadFile(ByVal Path As String) As String Dim ReadFileStream As FileStream Dim FileEncoding As New System.Text.ASCIIEncoding() Dim FileReader As StreamReader Dim HashData As New MD5CryptoServiceProvider() ReadFileStream = New FileStream(Path, FileMode.Open) FileReader = New StreamReader(ReadFileStream) Dim FileBytes = FileEncoding.GetBytes(FileReader.ReadToEnd) Dim FetchedContent = FileEncoding.GetString(HashData.ComputeHash(FileBytes)) FileReader.Close() ReadFileStream.Close() Return FetchedContent
And this is how to use:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If (CompareFiles("path of first file", "path of second file")) Then MsgBox("duplicate") Else MsgBox("diff") End If End Sub
I have a hot folder wherein my client sends a zip file and a back up folder that contains previous files from my client.
Now, what should be my modification of the above usage for me to compare the incoming file (for example test.zip) from hot folder to each file in the backup folder?
I write this code but no luck:
Dim dir As New DirectoryInfo(d:\backup) Dim zfiles As FileInfo() = dir.GetFiles("*.zip") Dim zfile As FileInfo For Each zfile In zfiles If (CompareFiles("c:\hotfolder\test.zip", "d:\backup" & zfile.ToString)) Then MsgBox("duplicate") Else MsgBox("different") End If Next