最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

CFileFind的Find,ReverseFind,Left,Right用法

运维笔记admin14浏览0评论

CFileFind的Find,ReverseFind,Left,Right用法

CFileFind的Find,ReverseFind,Left,Right用法

            CString cstrFileName = finder.GetFileName();CString cstrFilePath = finder.GetFilePath();//完整文件路径
#ifdef DEBUGcstrFilePath = "F:\\CVProject\\lens\\process\\11\\Image_r2_c8_step1.bmp";
#endif//OutputDebugString((LPCTSTR)(cstrFilePath + L"\n"));//输出文件名int pos1 = cstrFilePath.ReverseFind(_T('\\'));CString pathNoName = cstrFilePath.Left(pos1);//去掉文件名和斜杠int pos2 = pathNoName.ReverseFind(_T('\\'));//绝对位置CString fileDic = pathNoName.Right(pathNoName.GetLength()-pos2 - 1);//上级目录名

Find为从左往右查找“\\”出现的第一个位置,ReverseFind为从右往左查找“\\”出现的第一个位置。但是两者得到的位置都是从左往右的绝对位置。所以在得到上级目录名时,用Right函数得到从右往左(总长度-pos2-1)的部分。
这里得到的fileDic为“11”

发布评论

评论列表(0)

  1. 暂无评论