[C#]我真是笨透了,该怎样把C:\\aaa\\bbb\\a.txt的路径名和文件名分开 在C#中,得到一个文件的路径名和文件名string filepathname="C:\\aaa\\bbb\\a.txt";我该怎样把路径名和文件名分别保存到string path和string name中,我真是笨透了。谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 filepathname.Substring(filepathname.LastIndexOf("\\") + 1)这取的是名字.以此类推 string path =System.IO.Path.GetDirectoryName("string");string name =System.IO.Path.GetFileName("string");也不知道你说的是不是这个意思? string path =System.IO.Path.GetDirectoryName(filepathname);string name =System.IO.Path.GetFileName(filepathname); (C:\\aaa\\bbb\\a.txt).substring((C:\\aaa\\bbb\\a.txt).lastindexof("\\") +1); System.IO.Path.GetDirectoryName(filepathname);System.IO.Path.GetFileName(filepathname); 获取路径名:string path =System.IO.Path.GetDirectoryName(filepathname);获取文件名:string name =System.IO.Path.GetFileName(filepathname); 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();//获取一个值,该值指示指定的路径字符串是包含绝对路径信息还是包含相对路径信息。 string str = "C:\\aaa\\bbb\\a.txt";string[] strArr = str.Split('\\');str = strArr[strArr.Length - 1]; 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; string action ="C:\\aaa\\bbb\\a.txt";action = action.Substring(action.LastIndexOf("\\")+1); C#是否公开源代码? 初学,C#中如何将ASCII码值转换成int型数据 c++结构体转换成c# 请问想要做一个类似任务栏屏幕右下角里面的时钟,该找哪些关键词阿? 用C# 如何实现这个功能???? 求教:Gridview 绑定datatable,随机数据展示,出错 数据库打包安装,高手进来 关于AD操作的问题. c#的随机函数怎样用! 双引号的转义 有3个字段,现在要按其中两个的和从大到小排序,这个sql语句怎么写? DataBinder.Eval(参数1,参数2,参数3)
以此类推
string name =System.IO.Path.GetFileName("string");也不知道你说的是不是这个意思?
string name =System.IO.Path.GetFileName(filepathname);
System.IO.Path.GetFileName(filepathname);
string path =System.IO.Path.GetDirectoryName(filepathname);
获取文件名:
string name =System.IO.Path.GetFileName(filepathname);
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();//获取一个值,该值指示指定的路径字符串是包含绝对路径信息还是包含相对路径信息。
string[] strArr = str.Split('\\');
str = strArr[strArr.Length - 1];
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;
action = action.Substring(action.LastIndexOf("\\")+1);