2012-07-06 173 views
14

我如何獲得一個目錄的父,例如:你想如何找到路徑的父目錄?

string upDir = GetOneLvlUp(@"C:\AAA\BBB\CCC\DDD\"); 

Output: C:\AAA\BBB\CCC\ 
+1

可能的重複[如何在C#中找到父目錄?](http://stackoverflow.com/questions/6875904/how-do-i-find-the-parent-directory-in-c) – bfavaretto 2012-07-10 00:44:43

回答

29
upDir = Directory.GetParent(path).FullName; 
6
string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); 
string parentDir = Directory.GetParent(path).FullName;