MFC遍历所有的文档

83 阅读1分钟

遍历所有的文档

void CTestDlg::OnBnClickedButton1()
{
    // TODO: 在此添加控件通知处理程序代码 
    CString myDataPath,pathStr,datafile;
    GetDlgItemText(IDC_EDIT1,pathStr);
    myDataPath=pathStr+"\\*.*";
    CFileFind  find;
    BOOL bf=find.FindFile(myDataPath);
    while(bf)
    {
        bf=find.FindNextFile();
        if(!find.IsDots())
        {
            CString fdPath=find.GetFilePath();
            if(find.IsDirectory())
            {

            }
            else if(fdPath.Find(".xml")!=-1 || fdPath.Find(".XML")!=-1)
            {
                CXml xml;
                Log("正在处理文件 %s\r\n",fdPath);
                if(!xml.Open(fdPath))
                {
                    Log("文件打开失败%s\r\n",fdPath);
                    continue;
                }
                xml.SaveWithFormatted(fdPath,"UTF-8");
                xml.Close();
            }
        }
    }
    find.Close();
}