int CAT_OLC_DUTDlg::getFolderFile(CString pathStr)
{
CString myDataPath, fdPath; //设置路径变量
myDataPath = pathStr + L"\\*.*"; //文件夹路径 路径后面加*.*就会遍历该路径目录下的所有文件
CFileFind find; //例化CFileFind
BOOL bf = find.FindFile(myDataPath);
int a = 0;
while (bf)
{
bf = find.FindNextFile();
if (!find.IsDots())
{
CString nowfilename = find.GetFileName();//这一句要放在isDots之后。isDots是判断当前文件名是否是.或..
if (find.IsDirectory())
{
//如果是文件夹,跳过
continue;
}
else
{
//CreateTeatLog(_T("findfilename:")+ nowfilename);
CString fn = fileNames;//fileNames全局变量,配置文件里获取并赋值,包含所有需要查找的文件名的字串
std::string conName = (CStringA)fn;//转换为string好使用find方法 CString的Find只能找到单个字符
std::string nowFindName = (CStringA)nowfilename;
if (conName.find(nowFindName) != conName.npos) {//匹配到配置中的文件名
//匹配对应文件名更新二维码信息
int pos;
pos = nowFindName.find(".");
string strs = nowFindName.substr(0,pos );
CString prefixName = CA2T(strs.c_str());
if (HeadBarcode.Find(prefixName) < 0) {//判断二维码内容中是否已经有该信息,已经有该信息则不重复更新
HeadBarcode += prefixName + _T("=Pass$");
//输出log用于验证
CreateTeatLog(_T("QR code update content:")+ prefixName+ _T("=Pass$"));
//在更新二维码前清空显示内容控件 再显示更新后的内容
m_Edit.SetSel(0, -1);
m_Edit.ReplaceSel(_T(""));
Prepare2DBarcode(requestpngpath, imagename1, HeadBarcode);
m_Edit.SetSel(-1, 1);
m_Edit.ReplaceSel(_T("[Request]\r\n"));
m_Edit.ReplaceSel(HeadBarcode);
SetTimer(2, 100, 0);
a = 1;
}
}
}
}
}
find.Close();
return a;
}
void CAT_OLC_DUTDlg::Prepare2DBarcode(CString FileName,CString imgname,CString STR )
{
STR.Trim();
QRGenerator(STR);
}
本文介绍了一个C++函数getFolderFile,该函数用于遍历指定文件夹下的所有文件,并根据配置文件中的文件名列表来更新二维码内容。具体实现包括了文件查找、文件名匹配及二维码信息更新等步骤。

247

被折叠的 条评论
为什么被折叠?



