Languages/C#

C# - 상대 경로(Reletive Path)

라큐브 2022. 8. 18. 14:01

다른 언어를을 사용하면서 C#에서 "../.../test.exe" 형식으로 사용할 수 없을까 생각하다 고안한 방법입니다. 

static void Main()
{
    Console.WriteLine(ReletivePath("../PFolderFile.exe"));
    Console.WriteLine(ReletivePath("../../PFolderFile.exe"));
    Console.WriteLine(ReletivePath("../../../PFolderFile.exe"));
}

/// <summary>
/// 상대 경로를 절대 경로로 반환합니다.
/// </summary>
/// <param name="InternalPath"></param>
/// <returns></returns>
static string ReletivePath(string InternalPath = "")
{
    InternalPath = InternalPath.Replace("/", @"\");
    return Path.GetFullPath(InternalPath);
}

 

 

 




 

 

콘솔창에서 확인해보면 한 수준씩 뒤로 밀리는 걸 확인 할 수 있습니다.

 

반응형