2012-07-06 225 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;