Programming
C# – Compare Equality of two Paths
by admin on Mar.25, 2013, under Programming
This is an approach how I’d find out whether or not two directory paths are equal.
Case sensitive approach:
if (System.AppDomain.CurrentDomain.BaseDirectory.Replace("/", "\\").TrimEnd(new char[] { '\\' }).Equals(c.InstallationPath.Replace("/", "\\").TrimEnd(new char[] { '\\' }))) { // Paths are equal }
Case insensitive approach:
if (System.AppDomain.CurrentDomain.BaseDirectory.Replace("/", "\\").TrimEnd(new char[] { '\\' }).Equals(c.InstallationPath.Replace("/", "\\").TrimEnd(new char[] { '\\' }), StringComparison.CurrentCultureIgnoreCase)) { // Paths are equal }
It’s for sure not the most elegant way to do this but it works.