如何从路径(可能有文件名)中得到路径和文件名?

解决方案 »

  1.   

    判断路径的末尾字符串啊。比如用string有EndsWith()方法来判断路径是否以某个扩展名结尾,path.EndsWith(".doc");如有的话。再从最后一个"\"处开始截取,得到的子串就是文件名。
      

  2.   

         string s = "c:\\1\\2\\中文\\1.exe";
                System.IO.FileInfo f = new System.IO.FileInfo(s);
                MessageBox.Show( f.Name);
                MessageBox.Show( f.DirectoryName );
      

  3.   

    引用System.IO;Path.GetFileName
    Path.GetDirectoryName