TextBox1.Text &= "File Full Name: " & fi.FullName & vbNewLine TextBox1.Text &= "File Extension: " & fi.Extension & vbNewLine Dim f As FileStream = New FileStream(fi.FullName, FileMode.Open, FileAccess.Read, FileShare.Read, 8192) f = New FileStream(fi.FullName, FileMode.Open, FileAccess.Read, FileShare.Read, 8192) md5.ComputeHash(f) Dim hash As Byte() = md5.Hash Dim buff As StringBuilder = New StringBuilder Dim hashByte As Byte For Each hashByte In hash buff.Append(String.Format("{0:X2}", hashByte)) Next Dim MD5waarde As String = buff.ToString() f.Close() TextBox1.Text &= "Md5 waarde: " & MD5waarde & vbNewLine Dim g As FileStream = New FileStream((dest & fi.Name), FileMode.Open, FileAccess.Read, FileShare.Read, 8192) g = New FileStream((dest & fi.Name), FileMode.Open, FileAccess.Read, FileShare.Read, 8192) md5.ComputeHash(g) hash = md5.Hash buff = New StringBuilder For Each hashByte In hash buff.Append(String.Format("{0:X2}", hashByte)) Next Dim MD5dest As String = buff.ToString() g.Close() System.Threading.Thread.Sleep(5000) TextBox1.Text &= "Md5 waarde in KLWIN: " & MD5dest & vbNewLine If MD5waarde = MD5dest Then check = check + 1 Else Dim del As New FileInfo(dest & fi.Name) del.Delete() fi.MoveTo(dest & fi.Name) TextBox1.Text &= fi.Name & " vervangen" End If
I'm trying to compare the MD5 values of two files with the same name in different folders. if the values are not the same the file in one folder needs to be replaced by the other.
The program fails in this subroutine on the Delete() and MoveTo() because the files are in use. As far as I can establish they are in use because of the hash.
I thought f.Close() and g.Close() would prevent that from happening but obviously I was wrong.
Is there something else I need to close?