I tried to create a simple little application to make it easier to create the Update files for my main project, by just comparing files in two more or less similar folders and telling me what files are different. But it always gives me the following output when testing two completely similar folders:
C:\Users\there\Desktop\Folder 2\1.txt
C:\Users\there\Desktop\Folder 2\2.txt
My code:
private void FirstFolderBtn_Click(object sender, EventArgs e)
{
using (var fbd = new FolderBrowserDialog())
{
DialogResult result = fbd.ShowDialog();
if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath))
{
FirstFolderTB.Text = fbd.SelectedPath;
}
}
}
private void SecondFolderButton_Click(object sender, EventArgs e)
{
using (var fbd = new FolderBrowserDialog())
{
DialogResult result = fbd.ShowDialog();
if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath))
{
SecondFolderTB.Text = fbd.SelectedPath;
}
}
}
private void CompareBtn_Click(object sender, EventArgs e)
{
foreach(string file in Directory.GetFiles(FirstFolderTB.Text))
{
byte[] storedFileHash;
using (var md5 = MD5.Create())
{
using (var stream = File.OpenRead(file))
{
storedFileHash = md5.ComputeHash(stream);
}
using (var stream = File.OpenRead(file.Replace(FirstFolderTB.Text, SecondFolderTB.Text)))
{
if(storedFileHash != md5.ComputeHash(stream))
{
ResultTB.AppendText(file.Replace(FirstFolderTB.Text, SecondFolderTB.Text) + "\n");
}
}
}
}
}
I think I am just being dumb right now and overseeing some dumb mistake but I would appreciate if someone could help.
Thanks, Jan