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”