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 ;
}