From 7e48547483196f0c55adec43fc6067f72d91494a Mon Sep 17 00:00:00 2001 From: Jeffery Thompson Date: Tue, 8 May 2018 17:37:50 -0400 Subject: [PATCH] feat: add IcdPath.GetRelativePath(string, string) --- ICD.Common.Utils/IO/IcdPath.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ICD.Common.Utils/IO/IcdPath.cs b/ICD.Common.Utils/IO/IcdPath.cs index 6ee4a52..b1946bf 100644 --- a/ICD.Common.Utils/IO/IcdPath.cs +++ b/ICD.Common.Utils/IO/IcdPath.cs @@ -68,5 +68,17 @@ namespace ICD.Common.Utils.IO return Path.ChangeExtension(path, ext); } + + public static string GetRelativePath(string folder, string filespec) + { + Uri pathUri = new Uri(filespec); + // Folders must end in a slash + if (!folder.EndsWith(Path.DirectorySeparatorChar.ToString())) + { + folder += Path.DirectorySeparatorChar; + } + Uri folderUri = new Uri(folder); + return Uri.UnescapeDataString(folderUri.MakeRelativeUri(pathUri).ToString().Replace('/', Path.DirectorySeparatorChar)); + } } }