在C#中,得到一个文件的路径名和文件名string filepathname="C:\\aaa\\bbb\\a.txt";我该怎样把路径名和文件名分别保存到string path和string name中,我真是笨透了。谢谢
解决方案 »
- 新手求助! 条件查询并显示在datagridview中
- 在1秒内做16个ACCESS数据库语句操作并把结果在LABEL控件是哪个显示可以吗
- 关于DataGridView的AllowUsertoDeleteRows属性
- 那位高人帮我解释一下这个加密和解码代码。我是初学者。。。。
- C#中正则表达式的\1的用法?
- 在windows系统编写shell脚本
- RadioButtonList新添项的问题
- datagrid 打印時自適應欄寬的問題
- C#写的ftp服务端软件
- 根据控件名称来找到这个控件?
- 有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);