獲取指定資料夾的上級目錄
阿新 • • 發佈:2019-01-09
實現效果:
知識運用:
Directory類的GetParent方法 //檢索指定路徑的付資料夾 包括絕對路徑和相對路徑
public static DirectoryInfo GetParent (string path)
實現程式碼:
private void button1_Click(object sender, EventArgs e) { FolderBrowserDialog FBDialog = new FolderBrowserDialog(); if(FBDialog.ShowDialog()==DialogResult.OK) { textBox1.Text=FBDialog.SelectedPath; string str1=textBox1.Text; string str2=Directory.GetParent(str1).FullName; string myInfo="當前目錄是: "+str1+Environment.NewLine+"上級目錄是: "+str2; label2.Text=myInfo; } }