feat: Adding util methods for path comparisons

This commit is contained in:
Chris Cameron
2018-04-16 16:54:03 -04:00
parent ce54f953ba
commit 7065b0c567
3 changed files with 94 additions and 0 deletions

View File

@@ -185,6 +185,24 @@ namespace ICD.Common.Utils
return IcdFile.Exists(path) || IcdDirectory.Exists(path);
}
/// <summary>
/// Returns the path if the given path is already a directory or has a trailing slash.
/// Otherwise returns the parent directory name.
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
[PublicAPI]
public static string GetDirectoryNameFromPath(string path)
{
if (IcdDirectory.Exists(path))
return path;
if (path.EndsWith(IcdPath.DirectorySeparatorChar) || path.EndsWith(IcdPath.AltDirectorySeparatorChar))
return path;
return IcdPath.GetDirectoryName(path);
}
#endregion
}
}