I have 2 DirectoryInfo objects and want to check if they are pointing to the same directory. Besides comparing their Fullname, are there any other better ways
Inspired from here:
static public bool SameDirectory(string path1, string path2)
{
return (
0 == String.Compare(
System.IO.Path.GetFullPath(path1).TrimEnd('\\'),
System.IO.Path.GetFullPath(path2).TrimEnd('\\'),
StringComparison.InvariantCultureIgnoreCase))
;
}
Works for file too...
(BTW theoretically questions are duplicate, but this is the original and the other one is the most answered one...)
HTH