C#实现获取当前文件路径的上级路径

coding

界面:

声明:

textBox1.Text为指定文件路径:string path = @"F:\ABB-pragram\ABB工作站\ABB Station\Systems\SituationalTeaching_Carry\HOME";

textBox2.Text为得到的该指定文件路径的上级路径(通过:提取路径按钮实现)

代码:

 1using System;

2using System.Collections.Generic;

3using System.ComponentModel;

4using System.Data;

5using System.Drawing;

6using System.IO;

7using System.Linq;

8using System.Text;

9using System.Windows.Forms;

10

11namespace 文件路径测试

12{

13publicpartialclass Form1 : Form

14{

15public Form1()

16{

17InitializeComponent();

18}

19string path = @"F:\ABB-pragram\ABB工作站\ABB Station\Systems\SituationalTeaching_Carry\HOME";

20privatevoid button1_Click(object sender, EventArgs e)

21{

22 DirectoryInfo pathInfo = new DirectoryInfo(path);

23string newPath = pathInfo.Parent.FullName;

24this.textBox2.Text = newPath.ToString();

25}

26

27privatevoid Form1_Load(object sender, EventArgs e)

28{

29this.textBox1.Text = path.ToString();

30}

31}

32 }

View Code

显示结果:

源码下载:链接:https://pan.baidu.com/s/1K6EH1G1vSy2wRIXzgZlxuQ 密码:c0jd

以上是 C#实现获取当前文件路径的上级路径 的全部内容, 来源链接: utcz.com/z/509739.html

回到顶部