获取指定文件夹的上级目录

实现效果:

  

知识运用:

  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;
            }
        }

  

猜你喜欢

转载自www.cnblogs.com/feiyucha/p/10246529.html
今日推荐