Here we go. Correct any errors as necessary. Just wrote it on MPGH post reply, so yeahs. C# and Visual Basic versions provided.
You will need to put your MD5 hashes which you want to check against in an array, either hard coded or loaded from a file or from a website or however you want into a string[] called "MD5Hashes". You can change the variable names if you wish.
C#
Code:
string MD5file(string fileName)
{
FileStream file = new FileStream(fileName, FileMode.Open);
MD5 md5 = new MD5CryptoServiceProvider();
byte[] retVal = md5.ComputeHash(file);
file.Close();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < retVal.Length; i++)
{
sb.Append(retVal[i].ToString("x2"));
}
return sb.ToString();
}
int main()
{
string[] filePaths = Directory.GetFiles(@"C:\freedompeace");
foreach (string file in filePaths)
{
foreach (string MD5hash in MD5Hashes)
{
if (MD5file(file) == MD5hash)
{
File.Delete(file);
}
}
}
}
Visual Basic
Code:
Private Function MD5file(fileName As String) As String
Dim file As New FileStream(fileName, FileMode.Open)
Dim md5 As MD5 = New MD5CryptoServiceProvider()
Dim retVal As Byte() = md5.ComputeHash(file)
file.Close()
Dim sb As New StringBuilder()
For i As Integer = 0 To retVal.Length - 1
sb.Append(retVal(i).ToString("x2"))
Next
Return sb.ToString()
End Function
Private Function main() As Integer
Dim filePaths As String() = Directory.GetFiles("C:\freedompeace")
For Each file__1 As String In filePaths
For Each MD5hash As String In MD5Hashes
If MD5file(file__1) = MD5hash Then
File.Delete(file__1)
End If
Next
Next
End Function