如何获取目录的父级,例如:
string upDir = GetOneLvlUp(@"C:\AAA\BBB\CCC\DDD\");
Output: C:\AAA\BBB\CCC\
upDir = Directory.GetParent(path).FullName;
您想要的一切都在 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
string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string parentDir = Directory.GetParent(path).FullName;
var upDir = new DirectoryInfo(yourPath).Parent.FullName;