csharp
复制代码
// 读取文件夹,获取MD5值
var hashs = new HashAlgorithm[] { MD5.Create(), SHA1.Create(), SHA256.Create(), SHA384.Create(), SHA512.Create() };
var files = dir.GetFiles("*", SearchOption.AllDirectories).OrderBy(f => f.Name).Take(200);
foreach (var hash in hashs)
{
var map = new Dictionary<string, List<FileInfo>>();
sw.Restart();
foreach (var file in files)
{
using (var fs = file.OpenRead())
{
var md5 = BitConverter.ToString(hash.ComputeHash(fs));
if (!map.ContainsKey(md5))
map.Add(md5, new List<FileInfo>());
map[md5].Add(file);
}
}
sw.Stop();
var hash_name = hash.GetType().BaseType.Name;
Console.WriteLine($"{hash_name}:{map.Count},耗时:{sw.Elapsed.TotalMilliseconds}");
}