To make this work, you will need to adjust how the Equals()
function operates. My suggestion is as follows:
Step 1 - Make path
variables available to the Equals()
method:
class CompareDirs
{
static void Main(string[] args)
{
// Create two identical or different temporary folders
// on a local drive and change these file paths.
string pathA = @"C:\TestDir";
string pathB = @"C:\TestDir2";
...
becomes
class CompareDirs
{
private string pathA, pathB;
static void Main(string[] args)
{
// Create two identical or different temporary folders
// on a local drive and change these file paths.
pathA = @"C:\TestDir";
pathB = @"C:\TestDir2";
...
Step 2 - Change Equals()
method to consider this information:
I suggest using .replace(pathA, pathB)
to enable the directories of the files to be compared as if the path was the same. Thus any files that are in the same subdirectory structure will be have the same directory overall (after the replace operation has been performed).
public bool Equals(System.IO.FileInfo f1, System.IO.FileInfo f2)
{
return (f1.Name == f2.Name &&
f1.Length == f2.Length &&
f1.DirectoryName.replace(pathA, pathB) == f2.DirectoryName.replace(pathA, pathB) );
}