查找文件并转换为MD5值:
public void FindFile(string dirPath) //参数dirPath为指定的目录
{
//在指定目录及子目录下查找文件,在listBox1中列出子目录及文件
// DirectoryInfo Dir = new DirectoryInfo(dirPath);
string[] fileList = System.IO.Directory.GetFileSystemEntries(dirPath);
try
{
foreach (string d in fileList)//查找子目录
{
// FindFile(Dir + d.ToString() + "/");
//listBox1中填加目录名
byte[] result = Encoding.Default.GetBytes( d.ToString() + "/");
//txtSortNum为输入密码的文本框,需要加密的文件就写这
MD5 md5 = new MD5CryptoServiceProvider();
byte[] output = md5.ComputeHash(result);
//this.textBox2.Text = BitConverter.ToString(output).Replace("-", "");
listView1.Items.Add( d.ToString() + "/");
listView1.Items.Add(BitConverter.ToString(output).Replace("-", ""));
//txtTaskName为输出加密文本
if (System.IO.Directory.Exists(d))
{
FindFile(d);
}
}
//foreach (FileInfo f in Dir.GetFiles()) //查找文件
//{
// // listBox1.Items.Add(Dir + f.ToString()); //listBox1中填加文件名
// byte[] result = Encoding.Default.GetBytes(Dir + f.ToString() + "/");
// //txtSortNum为输入密码的文本框,需要加密的文件就写这
// MD5 md5 = new MD5CryptoServiceProvider();
// byte[] output = md5.ComputeHash(result);
// //this.textBox2.Text = BitConverter.ToString(output).Replace("-", "");
// listView1.Items.Add(Dir + f.ToString() + "/");
// listView1.Items.Add(BitConverter.ToString(output).Replace("-", ""));
//}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
c#查找文件并转换为MD5值
最新推荐文章于 2023-03-17 09:42:38 发布