This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// 引数1のディレクトリから見た引数2のファイルへの相対パスを取得する | |
/// </summary> | |
/// <param name="uri1">基準となるディレクトリへの絶対パス(最後は\で終わっている必要あり)</param> | |
/// <param name="uri2">目的のファイルへの絶対パス</param> | |
/// <returns>引数1のディレクトリから見た引数2のファイルへの相対パス</returns> | |
/// <example> | |
/// GetRelativePath(@"C:\Windows\System\", @"C:\Windows\file.txt") | |
/// 出力:..\file.txt | |
/// </example> | |
string GetRelativePath(string uri1, string uri2) | |
{ | |
Uri u1 = new Uri(uri1); | |
Uri u2 = new Uri(uri2); | |
Uri relativeUri = u1.MakeRelativeUri(u2); | |
string relativePath = relativeUri.ToString(); | |
relativePath.Replace('/', '\\'); | |
Console.WriteLine(relativePath); | |
return (relativePath); | |
} |