Click to See Complete Forum and Search --> : DirectoryInfo equality


cjard
October 24th, 2005, 12:21 PM
Im trying to see if one path is equal to another:

DirectoryInfo di1 = new FileInfo("c:\temp\hello.txt").Directory;
DirectoryInfo di2 = new DirectoryInfo("c:\temp");

Console.Out.writeLn( di1.Equals(di2) );


prints false.. but they reference the same location on disk.. is this a retardedness of directoryInfo?

darwen
October 24th, 2005, 01:34 PM
I wouldn't really expect this to work. In any case, the Equals method just compares the references to the objects, not their contents in this case.

Why don't you just compare the paths case-insensitively instead e.g.


static bool PathsEqual(string sPath1, string sPath2)
{
return string.Compare(sPath1, sPath2, true);
}


Darwen.