MFC 如何从字符串中分离文件名与路径

//得到目录名称
CString GetPathName(CString strPathName)
{
    int index = str.ReverseFind('\\');
    CString strPath = _T("");
    if(index >= 0)
    {
        strPath = strPathName.Left(index);
    }
    else
    {
        index = strPathName.ReverseFind('/');
        strPath = strPathName.Left(index);
    }    return strPath;
}//得到文件名称不包含扩展名
CString GetFileName(CString strPathName)
{
    CString strFileName = _T("");
    int index = strPathName.ReverseFind('\\');
    if(index > 0)
    {
        index ++;
        strFileName = strPathName.Mid(index);
        index = strFileName.ReverseFind('.');
        strFileName = strFileName.Left(index);
        return strFileName;
    }
    else 
    {
        index = strPathName.ReverseFind('/');
        index ++;
        strFileName = strPathName.Mid(index);
        index = strFileNa


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部