MD5-Hash for an entire folder

Hi everybody,

I want to check the integrity of all files in a directory.

I want to know if anyone knows how to perform a MD5-Hash for an entire folder, I confess I don’t really understand how to do it…

Thanks for your help.

You would need to open each file individually and read the contents in order to compute the hash. You could compute an individual hash value for each file, or a cumulative hash value for the entire contents of the folder.

e.g. this computes a cumulative hash for a list of files using the MD5Digest class:

Function HashFiles(FileList() As FolderItem) As String
  Dim hasher As New MD5Digest
  For i As Integer = 0 To Ubound(FileList)
    Dim bs As BinaryStream = BinaryStream.Open(FileList(i))
    Dim raw As String =  bs.Read(bs.Length)
    bs.Close
    hasher.Process(raw)
  Next
  Return EncodeHex(hasher.Value)
End Function

Doing a single file individually would be the same, just without the loop.

Hi Andrew,

Your method works perfectly !

Thank you very much for your help.