private string GetPath(string strPath)
{ string tempPath = str ;
string ResultPath = "" ;
while( tempPath.IndexOf(@"\") != -1)
{
ResultPath += tempPath.Substring(0,tempPath.IndexOf(@"\")+1) ;
tempPath = tempPath.Substring(tempPath.IndexOf(@"\")+1,tempPath.Length - tempPath.IndexOf(@"\")-1) ; }
return ResultPath ;
}
{ string tempPath = str ;
string ResultPath = "" ;
while( tempPath.IndexOf(@"\") != -1)
{
ResultPath += tempPath.Substring(0,tempPath.IndexOf(@"\")+1) ;
tempPath = tempPath.Substring(tempPath.IndexOf(@"\")+1,tempPath.Length - tempPath.IndexOf(@"\")-1) ; }
return ResultPath ;
}
解决方案 »
- 寻背包问题求解
- 谈谈我对C#之父谈话的解读
- 读串口数据问题
- 怎么用c#做一个自动登陆.net网站的程序,这个网站是有验证码的?
- dropdownlist的SelectedIndexChanged事件
- 如何依据数据BIND的值来决定如何显示?
- 请问深圳的师哥师姐们,我这样子在深圳找工作能给多少月薪?
- 怎么把程序中的每个变量传给水晶报表???比如我要统计1月到5月的入库数量,怎么把1月和5月这两个变量传递给水晶报表让他显示出来!
- C#修改XML,请进!!
- .Net是否允许低阶的语言功能,或者C#是否支持汇编
- ArithmeticException:算术运算中发生溢出或下溢?
- 关于数据邦定的一个问题!!先谢
private string GetPath(string strPath)
{ string tempPath = strPath; //写错了 :p
string ResultPath = "" ;
while( tempPath.IndexOf(@"\") != -1)
{
ResultPath += tempPath.Substring(0,tempPath.IndexOf(@"\")+1) ;
tempPath = tempPath.Substring(tempPath.IndexOf(@"\")+1,tempPath.Length - tempPath.IndexOf(@"\")-1) ; }
return ResultPath ;
}
如果我没有理解错误的话你不是想搜索文件吧?如果只是想获得指定文件的目录,C# 提供了完全明晰的支持,你可以:string myFile = @"C:\windows\1.gif";
FileInfo fObj = new FileInfo(myFile);MessageBox.Show("目录位于:" + fObj.DirectoryName);string myDir = @"C:\windows\Media";
DirectoryInfo dObj = new DirectoryInfo(myDir);MessageBox.Show("上级目录:" + dObj.Parent.FullName);
MessageBox.Show("根目录:" + dObj.Root.Name);