2009-06-07 2 views
79

C#에서 두 개의 파일 경로를 결합하려면 어떻게해야합니까?C#에서 두 경로를 결합하려면 어떻게해야합니까?

+6

두 경로를 결합하면 무엇을 의미합니까? 두 부분 또는 두 개의 다른 파일에있는 파일 경로? 두 부분으로 된 파일 경로가 System.IO.Path.Combine (path1, path2)을 사용합니다. more info here [http://msdn.microsoft.com/en-us/library/system.io.path.combine.aspx] – TheVillageIdiot

답변

129

당신은 아래의 예와 같이 Path.Combine()을 사용해야합니다 :

string basePath = @"c:\temp"; 
string filePath = "test.txt"; 
string combinedPath = Path.Combine(basePath, filePath); 
// produces c:\temp\test.txt 
+12

"filePath"에 절대 경로가 포함되어 있으면 Path.Combine은 " 파일 경로". 'string basePath = @ "c : \ temp \"; string filePath = @ "c : \ dev \ test.txt";/* 어떤 이유로 든 */ 문자열 결합 = Path.Combine (basePath, filePath); ' 은 @ "c : \ dev \ test.txt"를 생성합니다. –

관련 문제