FolderBrowserDialog pFBD = new FolderBrowserDialog();
String path = pFBD.SelectPath;
上面这句代码是返回的你选择的文件夹的路径,现在我要做的是要获取最后的文件夹的名字,不知道怎么做,当时用了
pFBD.RootFolder属性,获取的不是我需要的文件夹的名字。
比如:path = “C:\ProgramFiles\Text\test”;
     我想获取“test“这个名字,用代码该怎么写呢?
      
    

解决方案 »

  1.   

     string fileFullName = Path.GetFileName(path);
      

  2.   

                    FileInfo fileinfo = new FileInfo(fileFullName);
                    string fileName = fileinfo.Name;
      

  3.   

                    FileInfo fileinfo = new FileInfo(path);
                    string fileName = fileinfo.Name;
      

  4.   

    string fileName = path.Substring(path.LastIndexOf("\\") + 1);
      

  5.   


                FolderBrowserDialog DgFolder = new FolderBrowserDialog();
                if (DgFolder.ShowDialog() == DialogResult.OK)
                {
                    System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(DgFolder.SelectedPath);
                    MessageBox.Show(di.Name);
                }