The following can scan a directory, return all files within it and save that information to a .txt file, but how and where do I write the function to get the checksum of that file next to it?
Example: C:\Desktop\E01.txt | 32DC1515AFDB7DBBEE21363D590E5CEA
I would really appreciate any help with this.
private void btnScan_Click(object sender, EventArgs e)
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() == DialogResult.OK)
listBox1.Items.Clear();
string[] files = Directory.GetFiles(fbd.SelectedPath);
string[] dirs = Directory.GetDirectories(fbd.SelectedPath);
foreach (string file in files)
{
listBox1.Items.Add(file);
}
{
foreach (string dir in dirs)
{
listBox1.Items.Add(dir);
}
}
}
private void btnSave_Click(object sender, EventArgs e)
{
var saveFile = new SaveFileDialog();
saveFile.Filter = "Text (*.txt)|*.txt";
if (saveFile.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
using (var sw = new StreamWriter(saveFile.FileName, false))
foreach (var item in listBox1.Items)
sw.Write(item.ToString() + Environment.NewLine);
MessageBox.Show("This file was successfully saved.");
}