选择文件夹,遍历其中所有的Jpg图片

	CString m_FileDir;  
	BROWSEINFO bi;  
	ZeroMemory(&bi, sizeof(BROWSEINFO));  
	bi.hwndOwner = m_hWnd;  
	bi.ulFlags   = BIF_RETURNONLYFSDIRS;  
	LPITEMIDLIST pidl = SHBrowseForFolder(&bi);  
	BOOL bRet = FALSE;  
	TCHAR szFolder[MAX_PATH*2];  
	szFolder[0] = _T('/0');  
	if (pidl)  
	{  
		if (SHGetPathFromIDList(pidl, szFolder))    
			bRet = TRUE;  
		IMalloc *pMalloc = NULL;  
		if (SUCCEEDED(SHGetMalloc(&pMalloc)) && pMalloc)  
		{   
			pMalloc->Free(pidl);   
			pMalloc->Release();  
		}  
	}  



	HANDLE hFile;
	//LPCTSTR lpFileName = "C:\\Users\\panda\\Desktop\\任务集\\ColorIndex\\img\\database-1\\*.jpg";	//指定搜索目录和文件类型,如搜索d盘的音频文件可以是"D:\\*.mp3"
	CString temp1="\\*.jpg";
	LPCTSTR lpFileName=szFolder;
	CString temp2=lpFileName;
	CString temp3=temp2+temp1;
	lpFileName=(LPCTSTR)temp3;

	WIN32_FIND_DATA pNextInfo;	//搜索得到的文件信息将储存在pNextInfo中;
	CString imgpath;
	hFile = FindFirstFile(lpFileName,&pNextInfo);//请注意是 &pNextInfo , 不是 pNextInfo;
	if(hFile == INVALID_HANDLE_VALUE)
	{
		//搜索失败
		exit(-1);
	}
	do
	{
		if(pNextInfo.cFileName[0] == '.')//过滤.和..
			continue;

		//pout_text<<pNextInfo.cFileName<<endl;
		imgpath=temp2+"\\"+pNextInfo.cFileName;
		img_tst_path.push_back(imgpath.GetString());
		
		//cout<<"得到文件:"<<pNextInfo.cFileName<<endl;
	}while(FindNextFile(hFile,&pNextInfo));

你可能感兴趣的:(选择文件夹,遍历其中所有的Jpg图片)