Artemis.Engine.Utilities.DirectoryUtils.MakeRelativePath C# (CSharp) Method

MakeRelativePath() public static method

Return the difference between a root directory and a child directory. For example, MakeRelativePath("a\b\", "a\b\c\d\e") will return "c\d\e".
public static MakeRelativePath ( string rootDirectory, string childDirectory ) : String
rootDirectory string
childDirectory string
return String
        public static String MakeRelativePath(string rootDirectory, string childDirectory)
        {
            if (String.IsNullOrEmpty(rootDirectory))
            {
                throw new ArgumentNullException("rootDirectory");
            }
            if (String.IsNullOrEmpty(childDirectory))
            {
                throw new ArgumentNullException("childDirectory");
            }
            if (!IsChildDirectoryOf(rootDirectory, childDirectory))
            {
                throw new ArgumentException(
                    String.Format("`childDirectory` must be child of `rootDirectory`. " +
                                  "'{0}' is not a child directory of '{1}'.", childDirectory, rootDirectory));
            }
            var parentComponents = rootDirectory.Split(Path.DirectorySeparatorChar);
            var childComponents  = childDirectory.Split(Path.DirectorySeparatorChar);

            Debug.Assert(parentComponents.Length < childComponents.Length);

            int i = 0;
            var maxLen = parentComponents.Length;
            while (i < maxLen && parentComponents[i] == childComponents[i]) i++;

            return String.Join(Path.DirectorySeparatorChar.ToString(), childComponents.Skip(i));
        }