我现在想通过对话框获得文件夹的路径(不是文件)该怎么操作?CString FilePathName;
CFileDialog dlg(FALSE, _T(""), _T(""),OFN_OVERWRITEPROMPT|OFN_HIDEREADONLY,newfile,this);
dlg.m_ofn.lpstrTitle = _T("目标文件保存");  // 标题名
if(dlg.DoModal()==IDOK)
{
    FilePathName=dlg.GetPathName();
}
类似这一段仅仅是获取了某类型的文件的路径,文件夹的路径该怎么写?(newfile是指定的文件类型)

解决方案 »

  1.   

    GetFolderPath不知道是不是这个,没用过LZ可以试下
    获取到全路径了,要得到文件夹路径,处理下字符串不就可以了吗,找到最后个'\\',然后left下,如果我没理解错的话这样应该是可以的
      

  2.   

    CString SelectDirectory(CString strTitle)
    {
    BROWSEINFO bi;   
      CString strDirPath;
    LPITEMIDLIST pidl;   
    LPMALLOC pMalloc = NULL;   ZeroMemory(&bi, sizeof(bi));   
    bi.hwndOwner = NULL;   
    bi.pszDisplayName = NULL;   
    bi.lpszTitle = strTitle;   
    bi.ulFlags = BIF_EDITBOX|BIF_RETURNFSANCESTORS;
    bi.lParam = NULL;
    bi.iImage = 0;
    pidl = SHBrowseForFolder(&bi);   if(pidl)   
    {   
    SHGetPathFromIDList(pidl, (char*)(LPCTSTR)strDirPath);   
    }  
    return strDirPath;
    }
      

  3.   

    CString FilePathName;
    int n=FilePathName.ReverseFind('\\');
    if (n>=0)
    FilePathName=FilePathName.Left(n+1);