原目录 D:\Program Files\Tencent
想要的目录 D:\Program Files
using
System.IO;
//目录 D:\Administrator\Documents\TestData
//返回 D:\Administrator\Documents
private string GetDirectoryParentPath(string path)
{
DirectoryInfo d = new DirectoryInfo(path);
return d.Parent.FullName;
}
|
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show( GetDirectoryParentPath(@"D:\Administrator\Documents\TestData") );
} |