The solution I came up with, which worked out great, was to modify a set of code from my C# Recipe book that computed a hash of two files and compared the hash values. The new code accepts a file pattern, recursively finds all matching files (from the current directory), then writes out each files hash value and file name.
I executed the program on both systems, redirecting the output to a text file, then just had to compare the two text files. Note: Be careful that the FileHash program itself and any redirected output files are not included in the file pattern that you are searching on.
Example:
..\FileHash.exe *.* > ..\hashvalues.systemA.txt
using System;
using System.IO;
using System.Security.Cryptography;
namespace FileHash
{
class Program
{
static void Main(string[] args)
{
new Program().Run(args);
}
private void Run(string[] args)
{
// Create the hashing object.
string[] files = Directory.GetFiles(@".\", args[0], SearchOption.AllDirectories);
foreach (string file in files)
{
using (HashAlgorithm hashAlg = HashAlgorithm.Create())
{
using (FileStream fs = new FileStream(file, FileMode.Open))
{
// Calculate the hash for the files.
byte[] hashBytes = hashAlg.ComputeHash(fs);
// Compare the hashes.
Console.WriteLine(string.Format(
"{0} {1}",
BitConverter.ToString(hashBytes),
file));
}
}
}
}
}
}
No comments:
Post a Comment