AcTools.Utils.FileUtils.GetRelativePath C# (CSharp) Method

GetRelativePath() public static method

public static GetRelativePath ( [ filename, [ directory ) : string
filename [ Ex.: C:\Windows\System32\explorer.exe
directory [ Ex.: C:\Windows
return string
        public static string GetRelativePath([NotNull] string filename, [NotNull] string directory) {
            if (filename == null) throw new ArgumentNullException(nameof(filename));
            if (directory == null) throw new ArgumentNullException(nameof(directory));

            filename = filename.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
            directory = directory.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);

            if (!filename.StartsWith(directory) || directory.Length == 0) return filename;

            var result = filename.Substring(directory[directory.Length - 1].IsDirectorySeparator() ? directory.Length - 1 : directory.Length);
            return result.Length == 0 || !result[0].IsDirectorySeparator() ? filename : result.Substring(1);
        }
    }