Trouble comparing two directories
<p>I am trying to compare two directories to see what files are in directory 1 that are not in directory 2. I have the following code:</p>

<pre><code>System.IO.DirectoryInfo dir1 = new System.IO.DirectoryInfo(pathA);
System.IO.DirectoryInfo dir2 = new System.IO.DirectoryInfo(pathB);

IEnumerable&lt;System.IO.FileInfo&gt; list1 = dir1.GetFiles("*.PRN");
IEnumerable&lt;System.IO.FileInfo&gt; list2 = dir2.GetFiles("*.PRN");

IEnumerable&lt;System.IO.FileInfo&gt; list3 = list1.Except(list2);

Console.WriteLine("The following files are in list1 but not list2:");

foreach (var v in list3)
{
    Console.WriteLine(v);
}
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
</code></pre>

<p>When this runs, it clearly lists all the files that are in directory 1, but many of them are already in directory 2. I can see this by just looking through Windows Explorer and looking at file names. What am I missing?</p>

<p>EDIT:</p>

<p>I believe the problem is in the file compare section. I am trying to get it to ignore the case of the file extension. I have tried this:</p>

<pre><code>    class FileCompare : System.Collections.Generic.IEqualityComparer&lt;System.IO.FileInfo&gt;
{
    public FileCompare() { }

    public bool Equals(System.IO.FileInfo f1, System.IO.FileInfo f2)
    {
        //return (f1.Name.ToUpper == f2.Name.ToUpper &amp;&amp;
        //        f1.Length == f2.Length);

        return (string.Equals(f1.Name, f2.Name, StringComparison.OrdinalIgnoreCase) &amp;&amp; f1.Length == f2.Length);
    }

    public int GetHashCode(System.IO.FileInfo fi)
    {
        string s = String.Format("{0}{1}", fi.Name, fi.Length);
        return s.GetHashCode();
    }
}
</code></pre>

<p>But that is still not working. You can see I commented out another attempt to just make everything upper case in the comparison, but it wouldn't take that. </p>
