Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

File in use by hash


  • Please log in to reply

#1
Metallica

Metallica

    Spyware Veteran

  • GeekU Moderator
  • 33,101 posts
I must be having the end of the year blues.

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?
  • 0

Advertisements


#2
Metallica

Metallica

    Spyware Veteran

  • Topic Starter
  • GeekU Moderator
  • 33,101 posts
No longer an issue since I decided to replace all the files and then check if the MD5 matches the new version.
  • 0

#3
stettybet0

stettybet0

    Trusted Tech

  • Technician
  • 2,579 posts
Hey Metallica, I know it's too late, but just for fun, try Dispose instead of Close...
  • 0

#4
Metallica

Metallica

    Spyware Veteran

  • Topic Starter
  • GeekU Moderator
  • 33,101 posts
Thanks for trying stettybet0. :)
But it still crashes on "file in use"
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP