メソッドを使用して、特定のディレクトリに等しいファイルをグループ化するコードを書いていますhashCompute
。ほとんどの作業を完了しましたが、ファイルをグループ化できないようです。同じハッシュ値を持つファイルをグループ化したい。
これが私のコードのサンプルです:
public static void myhashedfiles()
{
string directory;
Console.WriteLine("please enter a folder name:");
directory = (Console.ReadLine());
if (directory.Length < 1)
{
Console.WriteLine("enter a directory or folder name!");
return;
}
DirectoryInfo dir = new DirectoryInfo(directory);
try
{
FileInfo[] files = dir.GetFiles("*.*", System.IO.SearchOption.AllDirectories);
HashAlgorithm hash = HashAlgorithm.Create();
byte[] hashValue;
foreach (FileInfo fInfo in files)
{
FileStream fileStream = fInfo.Open(FileMode.Open);
fileStream.Position = 0;
hashValue = hash.ComputeHash(fileStream);
PrintByteArray(hashValue);
Console.WriteLine(fInfo.Name);
fileStream.Close();
}
}
catch (DirectoryNotFoundException)
{
Console.WriteLine("Error: The directory specified could not be found.");
}
catch (IOException)
{
Console.WriteLine("Error: A file in the directory could not be accessed.");
}
}