如何找到路径的父目录?

时间:2012-07-06 13:35:32

标签: .net

如何获取目录的父级,例如:

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

Output:  C:\AAA\BBB\CCC\

4 个答案:

答案 0 :(得分:33)

upDir = Directory.GetParent(path).FullName;

答案 1 :(得分:7)

答案 2 :(得分:6)

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

答案 3 :(得分:0)

var upDir = new DirectoryInfo(yourPath).Parent.FullName;