ObjectARX CAD批量打印
struct resbuf rbBackGroundPlot;acedGetVar(采用T("BACKGROUNDPLOT"), &rbBackGroundPlot);
if (rbBackGroundPlot.restype == RTSHORT && rbBackGroundPlot.resval.rint != 0)
{
int nOld = rbBackGroundPlot.resval.rint;
rbBackGroundPlot.resval.rint = 0;
acedSetVar(采用T("BACKGROUNDPLOT"), &rbBackGroundPlot);
rbBackGroundPlot.resval.rint = nOld;
}
AcDbLayoutManager* pLayMan = acdbHostApplicationServices()->layoutManager();
if (NULL != pLayMan)
{
//get the active layout
AcDbLayout* pLayout = pLayMan->findLayoutNamed(pLayMan->findActiveLayout(TRUE), TRUE);//获得当前布局
AcDbObjectIdm采用layoutId = pLayout->objectId();//获得布局的Id
AcPlPlotInfo plotInfo;
AcDbPlotSettingsValidator* pPSV = acdbHostApplicationServices()->plotSettingsValidator();
plotInfo.setLayout(pLayout->objectId());//必须设置
AcDbPlotSettings* m采用pSetting = new AcDbPlotSettings(pLayout->modelType());
m采用pSetting->copyFrom(pLayout);
pPSV->refreshLists(m采用pSetting);
m采用pSetting->setShadePlot(AcDbPlotSettings::kAsDisplayed);
m采用pSetting->setShadePlotResLevel(AcDbPlotSettings::kNormal);
m采用pSetting->setScaleLineweights(false);
m采用pSetting->setPrintLineweights(true);
m采用pSetting->setPlotTransparency(false);
m采用pSetting->setPlotPlotStyles(true);
m采用pSetting->setDrawViewportsFirst(true);
m采用pSetting->setShowPlotStyles(true);
if (suffix == ".pdf")
{
es = pPSV->setPlotCfgName(m采用pSetting, L"DWG to PDF.pc3", L"ISO采用FULL采用BLEED采用A4采用(210.00采用x采用297.00采用MM)");//"ISO采用FULL采用BLEED采用A4采用(297.00采用x采用210.00采用MM)"
es = pPSV->setPlotPaperUnits(m采用pSetting, AcDbPlotSettings::kMillimeters);
pPSV->setPlotWindowArea(m采用pSetting, extent.minPoint().x, extent.minPoint().y, extent.maxPoint().x, extent.maxPoint().y);
pPSV->setPlotOrigin(m采用pSetting, (extent.minPoint().x + extent.maxPoint().x) / 2, (extent.minPoint().y + extent.maxPoint().y) / 2);
pPSV->setPlotType(m采用pSetting, AcDbPlotSettings::kWindow);
es = pPSV->setCustomPrintScale(m采用pSetting, 1.0, 采用ttof(bl) / 1000.0);//PDF
}
else
{
es = pPSV->setPlotCfgName(m采用pSetting, L"CASS采用RASTER采用JPG.pc3", L"UserDefinedRaster (1200.00 x 1600.00像素)");//"UserDefinedRaster (1782.00 x 1260.00像素)"
es = pPSV->setPlotPaperUnits(m采用pSetting, AcDbPlotSettings::kPixels);
es = pPSV->setPlotType(m采用pSetting, AcDbPlotSettings::kExtents);
es = pPSV->setCustomPrintScale(m采用pSetting, 1.0, 采用ttof(bl) / 18000.0);//JPG
}
es = pPSV->setPlotRotation(m采用pSetting, AcDbPlotSettings::k0degrees);
es = pPSV->setCurrentStyleSheet(m采用pSetting, L"acad.ctb");
//全部配置名称
/*AcArray<const ACHAR*> mMediaList;
pPSV->plotDeviceList(mMediaList);
std::vector<CString> arrMediaNames;
pPSV->canonicalMediaNameList(m采用pSetting, mMediaList);
for (int nIndex = 0; nIndex < mMediaList.length(); ++nIndex)
arrMediaNames.push采用back(mMediaList);*/
// Specify that we want our plot centered by AutoCAD...
es = pPSV->setPlotCentered(m采用pSetting, true);
es = pPSV->setUseStandardScale(m采用pSetting, FALSE);
pPSV->setZoomToPaperOnUpdate(m采用pSetting, true);
plotInfo.setOverrideSettings(m采用pSetting);
// 验证这些设置。
AcPlPlotInfoValidator validator;
validator.setMediaMatchingPolicy(AcPlPlotInfoValidator::kMatchEnabled);
es = validator.validate(plotInfo);
AcPlPlotEngine* pEngine = NULL;
if (Acad::eOk == AcPlPlotFactory::createPublishEngine(pEngine))
{
// Here is the progress dialog for the current plot process...
AcPlPlotProgressDialog* pPlotProgDlg = acplCreatePlotProgressDialog(acedGetAcadFrame()->m采用hWnd, false, 1);
pPlotProgDlg->setPlotMsgString(AcPlPlotProgressDialog::kDialogTitle, 采用T("Plot API Progress"));
pPlotProgDlg->setPlotMsgString(AcPlPlotProgressDialog::kCancelJobBtnMsg, 采用T("Cancel Job"));
pPlotProgDlg->setPlotMsgString(AcPlPlotProgressDialog::kCancelSheetBtnMsg, 采用T("Cancel Sheet"));
pPlotProgDlg->setPlotMsgString(AcPlPlotProgressDialog::kSheetSetProgressCaption, 采用T("Job Progress"));
pPlotProgDlg->setPlotMsgString(AcPlPlotProgressDialog::kSheetProgressCaption, 采用T("Sheet Progress"));
pPlotProgDlg->setPlotProgressRange(0, 100);
pPlotProgDlg->onBeginPlot();
pPlotProgDlg->setIsVisible(true);
es = pEngine->beginPlot(pPlotProgDlg);
AcPlPlotPageInfo pageInfo;
// Used to describe how the plot is to be made.
//AcPlPlotInfo plotInfo;
// First, set the layout to the specified layout
// (which is the current layout in this sample).
//plotInfo.setLayout(layoutId);// This is required.
// Now, override the layout settings with the plot settings
// we have been populating.
//plotInfo.setOverrideSettings(pPlotSettings);
// We need to validate these settings.
//AcPlPlotInfoValidator validator;
//validator.setMediaMatchingPolicy(AcPlPlotInfoValidator::kMatchEnabled);
//es = validator.validate(plotInfo);
// Begin document.The version we call is dependent
// on the plot-to-file status.
//const TCHAR* szDocName = acDocManager->curDocument()->fileName();
CString szDocName = acDocManager->curDocument()->fileName();
CString outPutFilePath = szDocName;
int n = outPutFilePath.ReverseFind('.');
outPutFilePath = outPutFilePath.Left(n);
//outPutFilePath +=".jpg";
outPutFilePath += suffix;
//if (m采用bPlotToFile)
es = pEngine->beginDocument(plotInfo, szDocName, NULL, 1, true, outPutFilePath);
//else
//es = pEngine->beginDocument(plotInfo, szDocName);
// Follow through sending commands to the engine,
// and notifications to the progress dialog.
pPlotProgDlg->onBeginSheet();
pPlotProgDlg->setSheetProgressRange(0, 100);
pPlotProgDlg->setSheetProgressPos(0);
es = pEngine->beginPage(pageInfo, plotInfo, true);
es = pEngine->beginGenerateGraphics();
es = pEngine->endGenerateGraphics();
es = pEngine->endPage();
pPlotProgDlg->setSheetProgressPos(100);
pPlotProgDlg->onEndSheet();
pPlotProgDlg->setPlotProgressPos(100);
es = pEngine->endDocument();
es = pEngine->endPlot();
// Destroy the engine
pEngine->destroy();
pEngine = NULL;
// and the progress dialog.
pPlotProgDlg->destroy();
}
else
{
// Ensure the engine is not already busy...
AfxMessageBox(L"Plot Engine is Busy...");
}
pLayout->close();
m采用pSetting->close();
}
void CMyPalette1ChildDlg::OnBnClickedButton15()
{
// TODO: 在此添加控件通知处理程序代码
AcApDocument* pDoc = acDocManager->curDocument();
if (pDoc == nullptr)
{
return;
}
string filePath = CW2A(pDoc->fileName());
//LPITEMIDLIST pidl=ParsePidlFromPath(filePath);
ACHAR szPath; //存放选择的目录路径
string path;
ZeroMemory(szPath, sizeof(szPath));
BROWSEINFO bi;
bi.hwndOwner = m采用hWnd;// 父窗口句柄
bi.pidlRoot = CSIDL采用DESKTOP;// 要显示的文件夾的根(Root) CSIDL采用DESKTOP
bi.pszDisplayName = szPath;// 保存被选取的文件夾路径的缓冲区
bi.lpszTitle = L"请选择文件夹的目录:";// 显示位于对话框左上部的标题
bi.ulFlags = BIF采用RETURNONLYFSDIRS;// 指定对话框的外观和功能的標志
bi.lpfn = NULL;// 处理事件的回调函数
bi.lParam = 0;// 应用程序传给回调函数的参数
bi.iImage = 0;// 保存被选取的文件夾的图片索引
//弹出选择目录对话框
LPITEMIDLIST lp = SHBrowseForFolder(&bi);
if (lp == NULL)
{
AfxMessageBox(L"无效的目录,请重新选择");
return;
}
SHGetPathFromIDList(lp, szPath);
LPMALLOC lpMalloc;
if (FAILED(SHGetMalloc(&lpMalloc)))
return;
lpMalloc->Free(lp);
lpMalloc->Release();
path = CW2A(szPath);
std::vector<std::string> files;
CGeometryOper::getAllFiles(path, files, "", ".dwg");
files.erase(std::remove(files.begin(), files.end(), filePath), files.end());
//acDocManager->lockDocument(pDoc, AcAp::kWrite, NULL, NULL, true);
//AcTransaction* pTrans = actrTransactionManager->startTransaction();
Acad::ErrorStatus es;
AutoCAD::IAcadApplication* pAcad = nullptr;
HRESULT hr = NOERROR;
LPDISPATCH pAcadDisp = acedGetIDispatch(TRUE);
hr = pAcadDisp->QueryInterface(AutoCAD::IID采用IAcadApplication, (void**)&pAcad);
if (SUCCEEDED(hr)) {
pAcadDisp->Release();
}
/*AutoCAD::IAcadPreferences* pPreferences;
AutoCAD::IAcadPreferencesFiles* pPreferFiles;
BSTR Path;
pAcad->get采用Preferences(&pPreferences);
pPreferences->get采用Files(&pPreferFiles);
pPreferFiles->get采用PrinterConfigPath(&Path);
CString CPath = Path;
SysFreeString(Path);
pPreferFiles->Release();
pPreferences->Release();*/
CString suffix = ".jpg";
acedInitGet(NULL, 采用T("J P"));
ACHAR szKeyword = { 0 };
int nRet = acedGetKword(采用T("\n请输入关键字确定打印方式[(J)JPG/(P)PDF]<J>:"), szKeyword);
if (RTCAN == nRet)
{
acutPrintf(采用T("\n取消打印"));
return;
}
else if (RTNONE == nRet)
{
//acutPrintf(采用T("\n使用默认值"));
}
else if (RTNORM == nRet)
{
if (采用tcscmp(szKeyword, 采用T("J")) == 0)
{
}
else if (采用tcscmp(szKeyword, 采用T("P")) == 0)
{
suffix = ".pdf";
}
}
for (int i = 0; i < files.size(); i++)
{
CString sfile = files.c采用str();
es = acDocManager->appContextOpenDocument(sfile);
if (eOk == es)
{
AcApDocument* tmpDoc = acDocManager->curDocument();
AcDbDatabase* pDb = tmpDoc->database();
pDb->closeInput();
pAcad->ZoomExtents();
pDb->updateExt(TRUE);
acDocManager->lockDocument(tmpDoc, AcAp::kRead, NULL, NULL, true);
AcTransactionManager* pTrans = tmpDoc->transactionManager();
//tmpDoc->pushDbmod();
CString bl;
AcDbExtents extent;
//获得模型空间的块表记录
AcDbBlockTableRecord* pBlkTblRcd = NULL;
AcDbBlockTableRecordPointer pBlkRcd(ACDB采用MODEL采用SPACE, pDb, AcDb::kForRead);
AcDbBlockTableRecordIterator* iter;
extent.addBlockExt(pBlkRcd);
pBlkRcd->newIterator(iter);
for (iter->start(); !iter->done(); iter->step())
{
AcDbObjectId id;
es = iter->getEntityId(id);
if (es != Acad::eOk || !id.isValid())
continue;
// TODO 处理实体
AcDbObjectPointer<AcDbEntity> jzdEnt(id, AcDb::kForRead);
if (Acad::eOk != jzdEnt.openStatus())
{
continue;
}
if (jzdEnt->isKindOf(AcDbText::desc())) {
AcDbText* pText = AcDbText::cast(jzdEnt);
CString text = pText->textString();
if (text.Find(L"1:") == 0 || text.Find(L"比例尺 1:") == 0)
{
int pos = text.Find(L":");
bl = text.Mid(pos + 1);
break;
}
}
else if (jzdEnt->isKindOf(AcDbBlockReference::desc()))
{
AcDbBlockReference* pBlkRef = AcDbBlockReference::cast(jzdEnt);
AcDbObjectId idBlkDef = pBlkRef->blockTableRecord();
AcDbBlockTableRecordPointer pBlkTblRcdp(idBlkDef, AcDb::kForRead);
if (Acad::eOk != pBlkTblRcdp.openStatus()) continue;
ACHAR* name;
pBlkTblRcdp->getName(name);
CString blockname = name;
if (name != NULL)acutDelString(name);
if (blockname.MakeLower().Find(L"gddjtk") == 0)
{
AcDbVoidPtrArray entitySet;
es = pBlkRef->explode(entitySet);
if (es != Acad::eOk)
{
acutPrintf(采用T("\n炸开块失败"));
}
else
{
for (int i = 0; i < entitySet.length(); i++)
{
AcDbEntity* pEnty = (AcDbEntity*)entitySet.at(i);
if (pEnty != NULL)
{
if (pEnty->isKindOf(AcDbText::desc())) {
AcDbText* pText = AcDbText::cast(pEnty);
CString text = pText->textString();
if (text.Find(L"1:") == 0 || text.Find(L"比例尺 1:") == 0)
{
int pos = text.Find(L":");
bl = text.Mid(pos + 1);
pEnty->close();
break;
}
}
pEnty->close();
}
}
}
entitySet.removeAll();
entitySet.setLogicalLength(0);
break;
}
//判断指定的块表记录是否包含属性定义
if (!pBlkTblRcdp->hasAttributeDefinitions())
{
continue;
}
//直接获取图块的属性迭代器
AcDbObjectIterator* pIter = pBlkRef->attributeIterator();
//无论图块是否有属性,迭代器一般不会为NULL
if (NULL == pIter)
{
acutPrintf(采用T("\n获取属性迭代器失败!"));
continue;
}
//设置判断是否能获取到属性
for (pIter->start(); !pIter->done(); pIter->step())
{
AcDbObjectId attribId = pIter->objectId();
AcDbObjectPointer<AcDbAttribute> pAttrib(attribId, AcDb::kForRead);
if (Acad::eOk != pAttrib.openStatus())
{
continue;
}
//方式一
CString strTag;
strTag = pAttrib->tag();
if (strTag == "比例尺" || strTag == "BLC")
{
CString strValue;
strValue = pAttrib->textString();
int pos = strValue.Find(L":");
bl = strValue.Mid(pos + 1);
break;
}
//方式二
/*ACHAR* szTag = pAttrib->tag();
ACHAR* szValue = pAttrib->textString();
if (szTag != NULL && szValue != NULL)
{
acutPrintf(采用T("\n属性名: %s 属性值: %s"), szTag, szValue);
}
else
{
acutPrintf(采用T("\n获取属性值失败!"), szTag, szValue);
}
if (szTag != NULL)
{
acutDelString(szTag);
}
if (szValue != NULL)
{
acutDelString(szValue);
}*/
}
//释放迭代器
delete pIter;
if (!bl.IsEmpty())
{
break;
}
}
}
// 释放迭代器对象,关闭快表记录
delete iter;
pBlkRcd.release(pBlkTblRcd);//智能指针变普通指针
pBlkTblRcd->close();
acDocManager->unlockDocument(tmpDoc);
pTrans->abortTransaction();
//pDb->saveAs(sfile);
//pDb->save();
//tmpDoc->formatForSave();
//tmpDoc->popDbmod();
if (!bl.IsEmpty())
{
struct resbuf rbBackGroundPlot;
acedGetVar(采用T("BACKGROUNDPLOT"), &rbBackGroundPlot);
if (rbBackGroundPlot.restype == RTSHORT && rbBackGroundPlot.resval.rint != 0)
{
int nOld = rbBackGroundPlot.resval.rint;
rbBackGroundPlot.resval.rint = 0;
acedSetVar(采用T("BACKGROUNDPLOT"), &rbBackGroundPlot);
rbBackGroundPlot.resval.rint = nOld;
}
AcDbLayoutManager* pLayMan = acdbHostApplicationServices()->layoutManager();
if (NULL != pLayMan)
{
//get the active layout
AcDbLayout* pLayout = pLayMan->findLayoutNamed(pLayMan->findActiveLayout(TRUE), TRUE);//获得当前布局
AcDbObjectIdm采用layoutId = pLayout->objectId();//获得布局的Id
AcPlPlotInfo plotInfo;
AcDbPlotSettingsValidator* pPSV = acdbHostApplicationServices()->plotSettingsValidator();
plotInfo.setLayout(pLayout->objectId());//必须设置
AcDbPlotSettings* m采用pSetting = new AcDbPlotSettings(pLayout->modelType());
m采用pSetting->copyFrom(pLayout);
pPSV->refreshLists(m采用pSetting);
m采用pSetting->setShadePlot(AcDbPlotSettings::kAsDisplayed);
m采用pSetting->setShadePlotResLevel(AcDbPlotSettings::kNormal);
m采用pSetting->setScaleLineweights(false);
m采用pSetting->setPrintLineweights(true);
m采用pSetting->setPlotTransparency(false);
m采用pSetting->setPlotPlotStyles(true);
m采用pSetting->setDrawViewportsFirst(true);
m采用pSetting->setShowPlotStyles(true);
if (suffix == ".pdf")
{
es = pPSV->setPlotCfgName(m采用pSetting, L"DWG to PDF.pc3", L"ISO采用FULL采用BLEED采用A4采用(210.00采用x采用297.00采用MM)");//"ISO采用FULL采用BLEED采用A4采用(297.00采用x采用210.00采用MM)"
es = pPSV->setPlotPaperUnits(m采用pSetting, AcDbPlotSettings::kMillimeters);
pPSV->setPlotWindowArea(m采用pSetting, extent.minPoint().x, extent.minPoint().y, extent.maxPoint().x, extent.maxPoint().y);
pPSV->setPlotOrigin(m采用pSetting, (extent.minPoint().x + extent.maxPoint().x) / 2, (extent.minPoint().y + extent.maxPoint().y) / 2);
pPSV->setPlotType(m采用pSetting, AcDbPlotSettings::kWindow);
es = pPSV->setCustomPrintScale(m采用pSetting, 1.0, 采用ttof(bl) / 1000.0);//PDF
}
else
{
es = pPSV->setPlotCfgName(m采用pSetting, L"CASS采用RASTER采用JPG.pc3", L"UserDefinedRaster (1200.00 x 1600.00像素)");//"UserDefinedRaster (1782.00 x 1260.00像素)"
es = pPSV->setPlotPaperUnits(m采用pSetting, AcDbPlotSettings::kPixels);
es = pPSV->setPlotType(m采用pSetting, AcDbPlotSettings::kExtents);
es = pPSV->setCustomPrintScale(m采用pSetting, 1.0, 采用ttof(bl) / 18000.0);//JPG
}
es = pPSV->setPlotRotation(m采用pSetting, AcDbPlotSettings::k0degrees);
es = pPSV->setCurrentStyleSheet(m采用pSetting, L"acad.ctb");
//全部配置名称
/*AcArray<const ACHAR*> mMediaList;
pPSV->plotDeviceList(mMediaList);
std::vector<CString> arrMediaNames;
pPSV->canonicalMediaNameList(m采用pSetting, mMediaList);
for (int nIndex = 0; nIndex < mMediaList.length(); ++nIndex)
arrMediaNames.push采用back(mMediaList);*/
// Specify that we want our plot centered by AutoCAD...
es = pPSV->setPlotCentered(m采用pSetting, true);
es = pPSV->setUseStandardScale(m采用pSetting, FALSE);
pPSV->setZoomToPaperOnUpdate(m采用pSetting, true);
plotInfo.setOverrideSettings(m采用pSetting);
// 验证这些设置。
AcPlPlotInfoValidator validator;
validator.setMediaMatchingPolicy(AcPlPlotInfoValidator::kMatchEnabled);
es = validator.validate(plotInfo);
AcPlPlotEngine* pEngine = NULL;
if (Acad::eOk == AcPlPlotFactory::createPublishEngine(pEngine))
{
// Here is the progress dialog for the current plot process...
AcPlPlotProgressDialog* pPlotProgDlg = acplCreatePlotProgressDialog(acedGetAcadFrame()->m采用hWnd, false, 1);
pPlotProgDlg->setPlotMsgString(AcPlPlotProgressDialog::kDialogTitle, 采用T("Plot API Progress"));
pPlotProgDlg->setPlotMsgString(AcPlPlotProgressDialog::kCancelJobBtnMsg, 采用T("Cancel Job"));
pPlotProgDlg->setPlotMsgString(AcPlPlotProgressDialog::kCancelSheetBtnMsg, 采用T("Cancel Sheet"));
pPlotProgDlg->setPlotMsgString(AcPlPlotProgressDialog::kSheetSetProgressCaption, 采用T("Job Progress"));
pPlotProgDlg->setPlotMsgString(AcPlPlotProgressDialog::kSheetProgressCaption, 采用T("Sheet Progress"));
pPlotProgDlg->setPlotProgressRange(0, 100);
pPlotProgDlg->onBeginPlot();
pPlotProgDlg->setIsVisible(true);
es = pEngine->beginPlot(pPlotProgDlg);
AcPlPlotPageInfo pageInfo;
// Used to describe how the plot is to be made.
//AcPlPlotInfo plotInfo;
// First, set the layout to the specified layout
// (which is the current layout in this sample).
//plotInfo.setLayout(layoutId);// This is required.
// Now, override the layout settings with the plot settings
// we have been populating.
//plotInfo.setOverrideSettings(pPlotSettings);
// We need to validate these settings.
//AcPlPlotInfoValidator validator;
//validator.setMediaMatchingPolicy(AcPlPlotInfoValidator::kMatchEnabled);
//es = validator.validate(plotInfo);
// Begin document.The version we call is dependent
// on the plot-to-file status.
//const TCHAR* szDocName = acDocManager->curDocument()->fileName();
CString szDocName = acDocManager->curDocument()->fileName();
CString outPutFilePath = szDocName;
int n = outPutFilePath.ReverseFind('.');
outPutFilePath = outPutFilePath.Left(n);
//outPutFilePath +=".jpg";
outPutFilePath += suffix;
//if (m采用bPlotToFile)
es = pEngine->beginDocument(plotInfo, szDocName, NULL, 1, true, outPutFilePath);
//else
//es = pEngine->beginDocument(plotInfo, szDocName);
// Follow through sending commands to the engine,
// and notifications to the progress dialog.
pPlotProgDlg->onBeginSheet();
pPlotProgDlg->setSheetProgressRange(0, 100);
pPlotProgDlg->setSheetProgressPos(0);
es = pEngine->beginPage(pageInfo, plotInfo, true);
es = pEngine->beginGenerateGraphics();
es = pEngine->endGenerateGraphics();
es = pEngine->endPage();
pPlotProgDlg->setSheetProgressPos(100);
pPlotProgDlg->onEndSheet();
pPlotProgDlg->setPlotProgressPos(100);
es = pEngine->endDocument();
es = pEngine->endPlot();
// Destroy the engine
pEngine->destroy();
pEngine = NULL;
// and the progress dialog.
pPlotProgDlg->destroy();
}
else
{
// Ensure the engine is not already busy...
AfxMessageBox(L"Plot Engine is Busy...");
}
pLayout->close();
m采用pSetting->close();
}
}
acDocManager->appContextCloseDocument(tmpDoc);
tmpDoc = nullptr;
}
sfile.ReleaseBuffer();
}
if (SUCCEEDED(hr)) {
pAcad->Release();
}
files.clear();
//actrTransactionManager->abortTransaction();
//acDocManager->unlockDocument(pDoc);
acutPrintf(采用T("\n完成!\n"));
}
void CGeometryOper::getAllFiles(const std::string& path, std::vector<std::string>& files, const string& fileName, const string& fileType, bool recursive)
{
//文件句柄
long long hFile = 0;
//文件信息
struct 采用finddata采用t fileinfo;
string p;
if ((hFile = 采用findfirst(p.assign(path).append("\\*").c采用str(), &fileinfo)) != -1) {
do {
if ((fileinfo.attrib & 采用A采用SUBDIR)) {//比较文件类型是否是文件夹
if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0) {
//files.push采用back(p.assign(path).append("\\").append(fileinfo.name));
//递归搜索
if (recursive)
{
getAllFiles(p.assign(path).append("\\").append(fileinfo.name), files, fileName, fileType);
}
}
}
else {
string name = fileinfo.name;
string ImgNameNoTag = name.substr(0, name.rfind("."));//获取不带后缀的文件名
string ImgNameTag = name.substr(name.rfind("."), name.length());//获取后缀名
if (fileType.empty())
{
if (fileName.empty())
{
files.push采用back(p.assign(path).append("\\").append(fileinfo.name));
}
else
{
if (ImgNameNoTag.find(fileName) != string::npos)
{
files.push采用back(p.assign(path).append("\\").append(fileinfo.name));
}
}
}
else
{
transform(ImgNameTag.begin(), ImgNameTag.end(), ImgNameTag.begin(), ::tolower);
if (ImgNameTag.find(fileType) != string::npos)
{
if (fileName.empty())
{
files.push采用back(p.assign(path).append("\\").append(fileinfo.name));
}
else
{
if (ImgNameNoTag.find(fileName) != string::npos)
{
files.push采用back(p.assign(path).append("\\").append(fileinfo.name));
}
}
}
}
}
} while (采用findnext(hFile, &fileinfo) == 0);//寻找下一个,成功返回0,否则-1
采用findclose(hFile);
}
}
页:
[1]