如    E:\test\test.pro;
怎么获得   E:\test\

解决方案 »

  1.   

    用CString的函数找最后的那个'\',然后在用Left或者Mid来截取
      

  2.   


    CString strTmp(_T("E:\\test\\test.pro"));TCHAR chTmp[MAX_PATH];
    int nLength = strTmp.GetLength();
    memcpy(chTmp, strTmp, nLength *sizeof(TCHAR));
    chTmp[nLength] = _T('\0');
    PathRemoveFileSpec(chTmp);CString strResult = chTmp;
    需要包含相应的头文件。。
    #include <Shlwapi.h>
      

  3.   

      代码如下:      
            TCHAR szFilePath[MAX_PATH + 1]; 
    GetModuleFileName(NULL, szFilePath, MAX_PATH); 
    char cha=_T('\\');
    TCHAR *ch=_tcsrchr(szFilePath, cha);
    ch[1] = 0;//删除文件名,只获得路径
    FolderPath = szFilePath;
      

  4.   


    可以参看我的博客:
    http://blog.csdn.net/p40614021/article/details/6699794
      

  5.   


    CString strFullPath = _T("E:\\test\\text.txt"");CString strPath;
    strPath = strFullPath.Left(strFullPath.ReverseFind('\\'));MessageBox(strPath);//e:\test