Thanks in advance for any assistance. I'm not even sure if this is possible, but I'm trying to get a list of duplicate files using their hashes to identify the list of files associated with the hashes.
I have this below:
Dictionary<FileHash, string[]> FindDuplicateFiles(string searchFolder)
{
Directory.GetFiles(searchFolder, "*.*")
.Select(
f => new
{
FileName = f,
FileHash = Encoding.UTF8.GetString(new SHA1Managed()
.ComputeHash(new FileStream(f,
FileMode.
OpenOrCreate,
FileAccess.Read)))
})
.GroupBy(f => f.FileHash)
.Select(g => new
{
FileHash = g.Key,
Files = g.Select(z => z.FileName).ToList()
})
.GroupBy(f => f.FileHash)
.Select(g => new {FileHash = g.Key, Files = g.Select(z => z.Files).ToArray()});
It compiles fine, but I'm just curious whether there's even a way to manipulate the results to return a Dictionary.
Any suggestions, alternatives, critiques would be greatly appreciated.