C#获取程序的前一目录
来源:百度知道 编辑:UC知道 时间:2024/06/25 22:16:39
如 c:\1\2\3获取出来是c:\1\2
举例说明
string strPath =c:\1\2\3;
string strPath1 = strPath.substring(0,strPath.lastIndexOf("\")-1)
strPath1 即使需要取得的目录字符串
把字符串用"\"分割成数组,再组合起来...
用下面的方法可以实现
using System.IO;
DirectoryInfo directoryInfo = Directory.GetParent(@"C:\WINDOWS\system32");
MessageBox.Show(directoryInfo.FullName);