如何获取目录的父级,例如:
string upDir = GetOneLvlUp(@"C:\AAA\BBB\CCC\DDD\");
Output: C:\AAA\BBB\CCC\
答案 0 :(得分:33)
upDir = Directory.GetParent(path).FullName;
答案 1 :(得分:7)
您想要的一切都在Directory类中:
http://msdn.microsoft.com/en-us/library/system.io.directory.aspx
特别是,GetParent:
http://msdn.microsoft.com/en-us/library/system.io.directory.getparent.aspx
答案 2 :(得分:6)
string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string parentDir = Directory.GetParent(path).FullName;
答案 3 :(得分:0)
var upDir = new DirectoryInfo(yourPath).Parent.FullName;