在C#中,得到一个文件的路径名和文件名string filepathname="C:\\aaa\\bbb\\a.txt";我该怎样把路径名和文件名分别保存到string path和string name中,我真是笨透了。谢谢

解决方案 »

  1.   

    filepathname.Substring(filepathname.LastIndexOf("\\") + 1)这取的是名字.
    以此类推
      

  2.   

    string path =System.IO.Path.GetDirectoryName("string");
    string name =System.IO.Path.GetFileName("string");也不知道你说的是不是这个意思?
      

  3.   

    string path =System.IO.Path.GetDirectoryName(filepathname);
    string name =System.IO.Path.GetFileName(filepathname);
      

  4.   

    (C:\\aaa\\bbb\\a.txt).substring((C:\\aaa\\bbb\\a.txt).lastindexof("\\") +1);
      

  5.   

    System.IO.Path.GetDirectoryName(filepathname);
    System.IO.Path.GetFileName(filepathname);
      

  6.   

    获取路径名:
    string path =System.IO.Path.GetDirectoryName(filepathname);
    获取文件名:
    string name =System.IO.Path.GetFileName(filepathname);
      

  7.   

    path=@"c:\test\a.txt";ChangeExtension=System.IO.Path.ChangeExtension(path,".old");//更改路径字符串的扩展名。 
    CombinePath=System.IO.Path.Combine(@"c:\","b.txt");//合并两个路径字符串。 
    DirectoryName=System.IO.Path.GetDirectoryName(path);//返回指定路径字符串的目录信息。 
    Extension=System.IO.Path.GetExtension(path);//返回指定的路径字符串的扩展名。 
    FileName=System.IO.Path.GetFileName(path);//返回指定路径字符串的文件名和扩展名。 
    FileNameWithoutExtension=System.IO.Path.GetFileNameWithoutExtension(path); //返回不具有扩展名的指定路径字符串的文件名。 
    FullPath=System.IO.Path.GetFullPath(path);//返回指定路径字符串的绝对路径。 
    PathRoot=System.IO.Path.GetPathRoot(path);//获取指定路径的根目录信息。 
    TempFileName=System.IO.Path.GetTempFileName();//返回唯一临时文件名并在磁盘上通过该名称创建零字节文件。 
    TempPath=System.IO.Path.GetTempPath();//返回当前系统的临时文件夹的路径。 
    HasExtension=System.IO.Path.HasExtension(path).ToString();//确定路径是否包括文件扩展名。 
    IsPathRooted=System.IO.Path.IsPathRooted(path).ToString();//获取一个值,该值指示指定的路径字符串是包含绝对路径信息还是包含相对路径信息。
      

  8.   

    string str = "C:\\aaa\\bbb\\a.txt";
    string[] strArr = str.Split('\\');
    str = strArr[strArr.Length - 1];
      

  9.   

    string str = "C:\\aaa\\bbb\\a.txt";
    string strName = "";
    string strPath = "";
    string[] strArr = str.Split('\\');
    strName = strArr[strArr.Length - 1];
    strPath = str.Replace(strName,"");或者
    string str = "C:\\aaa\\bbb\\a.txt";
    string strName = "";
    string strPath = "";
    System.IO.FileInfo fInfo = new System.IO.FileInfo(str);
    strName = fInfo.Name ;
    strPath = fInfo.DirectoryName;
      

  10.   

    string action ="C:\\aaa\\bbb\\a.txt";
    action = action.Substring(action.LastIndexOf("\\")+1);