【MFC】查找指定路径下的指格式,并放到vector中

MFC下比较实用的一段代码,需要包含stdarg.h 
注意参数要以 ":End:" 结尾

//
//函数功能:查找指定路径下的指格式,并放到vector中
//参数说明:
//strPath   ---  指定文件路径
//Vector    ---  用于存放查找结果的容器
//strSuffix ---  指定文件名包含的字段 如 .txt  Log2014*.log
// ...      ---  扩展参数,必须以 _T(":End:") 结尾
//By 冉瑞元 2014-8-7
int CDlgStationInfo::InitFileList(CString strPath ,std::vector<CString> &Vector_File,CString strSuffix,...){
	
	if (strSuffix == _T(":End:")) return 0;
	int resCount = 0;
	CString tempSuffix;
	tempSuffix.Format(strSuffix);
	va_list arg_ptr;
	va_start(arg_ptr , strSuffix);
	CFileFind finder;
	CString tempFileName;
	CString strCompletPath;
	do 
	{
		strCompletPath.Format(strPath + _T("*") + tempSuffix + _T("*"));
		BOOL bRes = finder.FindFile(strCompletPath);
		while(bRes){
			bRes = finder.FindNextFile();
			tempFileName = finder.GetFileName();
			Vector_File.push_back(tempFileName);
			resCount++;
		}
		tempSuffix.Format(_T("%s"),va_arg(arg_ptr , CString));
	} while (tempSuffix != _T(":End:"));
	va_end(arg_ptr);
	return resCount ;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值