Last active
April 27, 2017 13:41
-
-
Save kuttsun/3596e9a2d93ebe80b51b3a734111a51b to your computer and use it in GitHub Desktop.
This file contains hidden or 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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment