界面:
聲明:
textBox1.Text為指定文件路徑:string path = @"F:\ABB-pragram\ABB工作站\ABB Station\Systems\SituationalTeaching_Carry\HOME";
textBox2.Text為得到的該指定文件路徑的上級路徑(通過:提取路徑按鈕實現)
代碼:

1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.IO; 7 using System.Linq; 8 using System.Text; 9 using System.Windows.Forms; 10 11 namespace 文件路徑測試 12 { 13 public partial class Form1 : Form 14 { 15 public Form1() 16 { 17 InitializeComponent(); 18 } 19 string path = @"F:\ABB-pragram\ABB工作站\ABB Station\Systems\SituationalTeaching_Carry\HOME"; 20 private void button1_Click(object sender, EventArgs e) 21 { 22 DirectoryInfo pathInfo = new DirectoryInfo(path); 23 string newPath = pathInfo.Parent.FullName; 24 this.textBox2.Text = newPath.ToString(); 25 } 26 27 private void Form1_Load(object sender, EventArgs e) 28 { 29 this.textBox1.Text = path.ToString(); 30 } 31 } 32 }
顯示結果:
源碼下載:鏈接:https://pan.baidu.com/s/1K6EH1G1vSy2wRIXzgZlxuQ 密碼:c0jd