12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457 |
- #include "StdAfx.h"
- #include "filehelp.h"
- #include <shlwapi.h>
- // 排序和乱序使用stl;
- #include <cstdlib>
- #include <ctime>
- #include <algorithm>
- int myrandom(int i) { return std::rand() % i; }
- filehelpImpl::filehelpImpl(void)
- {
-
- }
- filehelpImpl::~filehelpImpl(void)
- {
- }
- /************************************************************************/
- /* 函数:[2/21/2017 Jeff];
- /* 描述:;
- /* 参数:;
- /* [IN] :;
- /* [OUT] :;
- /* [IN/OUT] :;
- /* 返回:void;
- /* 注意:;
- /* 示例:;
- /*
- /* 修改:;
- /* 日期:;
- /* 内容:;
- /************************************************************************/
- void filehelpImpl::random(IN STR_VEC& vtContent, IN BOOL bSort /* = TRUE */)
- {
- if (bSort)
- {//排序;
- std::sort(vtContent.begin(), vtContent.end());
- }
- else
- {//乱序;
- //设置随即数生成器的种子;
- std::srand(unsigned(std::time(0)));
- std::random_shuffle(vtContent.begin(), vtContent.end(), myrandom);
- }
- }
- /************************************************************************/
- /* 函数:[2/21/2017 Jeff];
- /* 描述:;
- /* 参数:;
- /* [IN] :;
- /* [OUT] :;
- /* [IN/OUT] :;
- /* 返回:void;
- /* 注意:;
- /* 示例:;
- /*
- /* 修改:;
- /* 日期:;
- /* 内容:;
- /************************************************************************/
- void filehelpImpl::split(OUT vector<TString>& vtSplit, IN const TString str, IN const TString strSplit)
- {
- if (str.size() == 0 || strSplit.size() == 0)
- return;
- INT nIndex = 0;
- vtSplit.clear();
- TString strtmp = str;
- TString strtmp2;
- do
- {
- if (TString::npos != (nIndex = strtmp.find_first_of(strSplit)))
- {
- strtmp2 = strtmp.substr(0, nIndex);
- if (strtmp2.size())vtSplit.push_back(strtmp2);
- strtmp = strtmp.substr(nIndex + strSplit.size());
- }
- } while (strtmp.find_first_of(strSplit) != TString::npos);
- if (strtmp.size())
- vtSplit.push_back(strtmp);
- }
- /************************************************************************/
- /* 函数:[2/19/2017 Jeff];
- /* 描述:保留指定的扩展名文件;
- /* 参数:;
- /* [IN] keepExt:要保留的扩展名;
- /* [OUT] vtfiles:要提取保留扩展名的文件数组;
- /* [IN/OUT] :;
- /* 返回:void;
- /* 注意:;
- /* 示例:;
- /*
- /* 修改:;
- /* 日期:;
- /* 内容:;
- /************************************************************************/
- void filehelpImpl::keepdownbyext(IN const TString &keepExt, IN STR_VEC &vtfiles)
- {
- if (keepExt.find(_T("*.*")) != TString::npos) return;
- if (vtfiles.size() == 0) return;
- // 获取复制扩展名;
- int nIndex = 0;
- TString strtmp;
- TString strRemainExt(keepExt);
- strRemainExt.append(_T("|"));
- STR_VEC vtRemainExt;
- // 将所有扩展名解析到数组里;
- do
- {
- nIndex = strRemainExt.find(_T('|'));
- if (nIndex != TString::npos)
- {
- strtmp = strRemainExt.substr(0, nIndex);
- strRemainExt = strRemainExt.substr(nIndex + 1);
- if (strtmp.compare(_T("*.*")))
- vtRemainExt.push_back(strtmp);
- }
- } while (strRemainExt.find(_T('|')) != TString::npos);
- STR_VEC vtresult;
- // 过滤非复制扩展名的文件,同时去掉缩略图,保留指定复制扩展名的文件;
- for (STR_VEC::iterator itExt = vtRemainExt.begin(); itExt != vtRemainExt.end(); itExt++)
- {
- for (STR_VEC::iterator it = vtfiles.begin(); it != vtfiles.end();)
- {
- if (match(itExt->substr(1), it->c_str()))
- {
- vtresult.push_back(*it);
- it = vtfiles.erase(it);
- }
- else
- it++;
- }
- }
- vtfiles.clear();
- for ( STR_VEC::iterator it = vtresult.begin(); it != vtresult.end(); it++ )
- {
- vtfiles.push_back(*it);
- }
- }
- void filehelpImpl::keepdownbyext(IN const TString &keepExt, IN const STR_VEC &vtfiles, OUT STR_VEC &vtresult)
- {
- if (keepExt.find(_T("*.*")) != TString::npos) return;
- if (vtfiles.size() == 0) return;
- // 获取复制扩展名;
- int nIndex = 0;
- TString strtmp;
- TString strRemainExt(keepExt);
- strRemainExt.append(_T("|"));
- STR_VEC vtRemainExt;
- // 将所有扩展名解析到数组里;
- do
- {
- nIndex = strRemainExt.find(_T('|'));
- if (nIndex != TString::npos)
- {
- strtmp = strRemainExt.substr(0, nIndex);
- strRemainExt = strRemainExt.substr(nIndex + 1);
- if (strtmp.compare(_T("*.*")))
- vtRemainExt.push_back(strtmp);
- }
- } while (strRemainExt.find(_T('|')) != TString::npos);
- #if 0
- // 过滤非复制扩展名的文件,同时去掉缩略图,保留指定复制扩展名的文件;
- for (STR_VEC::iterator itExt = vtRemainExt.begin(); itExt != vtRemainExt.end(); itExt++)
- {
- for (STR_VEC::const_iterator it = vtfiles.begin(); it != vtfiles.end(); it++)
- {
- if (match(itExt->substr(1), it->c_str()))
- {
- vtresult.push_back(*it);
- }
- }
- }
- #else
- STR_VEC vt_files;
- for (STR_VEC::const_iterator it = vtfiles.begin(); it != vtfiles.end(); it++ )
- {// 不能直接用vtresult来复制,因为如果vtresult不为空的情况下,会有异常出现;
- vt_files.push_back(*it);
- }
- for (STR_VEC::iterator itExt = vtRemainExt.begin(); itExt != vtRemainExt.end(); itExt++)
- {
- for (STR_VEC::iterator it = vt_files.begin(); it != vt_files.end(); )
- {
- if (match(itExt->substr(1), it->c_str()))
- {
- vtresult.push_back(*it);
- it = vt_files.erase(it);
- }
- else
- it++;
- }
- }
- #endif
- }
- /************************************************************************/
- /* 函数:keepoutext[2/19/2017 Jeff];
- /* 描述:移除指定扩展名的文件;
- /* 参数:;
- /* [IN] :;
- /* [OUT] :;
- /* [IN/OUT] :;
- /* 返回:void;
- /* 注意:;
- /* 示例:;
- /*
- /* 修改:;
- /* 日期:;
- /* 内容:;
- /************************************************************************/
- void filehelpImpl::keepoutbyext(IN const TString &removeext, IN STR_VEC &vtfiles)
- {
- if (removeext.find(_T("*.*")) != TString::npos) return;
- if (vtfiles.size() == 0) return;
- // 获取复制扩展名;
- int nIndex = 0;
- TString strtmp;
- TString strRemoveExt(removeext);
- strRemoveExt.append(_T("|"));
- STR_VEC vtRemoveExt;
- // 将所有扩展名解析到数组里;
- do
- {
- nIndex = strRemoveExt.find(_T('|'));
- if (nIndex != TString::npos)
- {
- strtmp = strRemoveExt.substr(0, nIndex);
- strRemoveExt = strRemoveExt.substr(nIndex + 1);
- if (strtmp.compare(_T("*.*")))
- vtRemoveExt.push_back(strtmp);
- }
- } while (strRemoveExt.find(_T('|')) != TString::npos);
- // 过滤非复制扩展名的文件,同时去掉缩略图,保留指定复制扩展名的文件;
- for (STR_VEC::iterator itExt = vtRemoveExt.begin(); itExt != vtRemoveExt.end(); itExt++)
- {
- for (STR_VEC::iterator it = vtfiles.begin(); it != vtfiles.end();)
- {
- if (match(itExt->substr(1), it->c_str()))
- {
- it = vtfiles.erase(it);
- }
- else
- it++;
- }
- }
- }
- void filehelpImpl::keepoutbyext(IN const TString &removeext, IN const STR_VEC &vtfiles, OUT STR_VEC &vtresult)
- {
- if (removeext.find(_T("*.*")) != TString::npos) return;
- if (vtfiles.size() == 0) return;
- // 获取复制扩展名;
- int nIndex = 0;
- TString strtmp;
- TString strRemoveExt(removeext);
- strRemoveExt.append(_T("|"));
- STR_VEC vtRemoveExt;
- // 将所有扩展名解析到数组里;
- do
- {
- nIndex = strRemoveExt.find(_T('|'));
- if (nIndex != TString::npos)
- {
- strtmp = strRemoveExt.substr(0, nIndex);
- strRemoveExt = strRemoveExt.substr(nIndex + 1);
- if (strtmp.compare(_T("*.*")))
- vtRemoveExt.push_back(strtmp);
- }
- } while (strRemoveExt.find(_T('|')) != TString::npos);
- // 复制到新容器中;
- STR_VEC vt_files;
- for (STR_VEC::const_iterator it = vtfiles.begin(); it != vtfiles.end(); it++ )
- {// 不能直接用vtresult来复制,因为如果vtresult不为空的情况下,会有异常出现;
- vt_files.push_back(*it);
- }
- // 过滤非复制扩展名的文件,同时去掉缩略图,保留指定复制扩展名的文件;
- for (STR_VEC::iterator itExt = vtRemoveExt.begin(); itExt != vtRemoveExt.end(); itExt++)
- {
- for (STR_VEC::iterator it = vt_files.begin(); it != vt_files.end();)
- {
- if (match(itExt->substr(1), it->c_str()))
- {
- vtresult.push_back(*it);
- it = vt_files.erase(it);
- }
- else
- it++;
- }
- }
- }
- void filehelpImpl::keepdowbyname(IN const STR_VEC &vtnames)
- {
- if ( m_pvtfiles == NULL || m_pvtnames == &vtnames )
- return;
- INT nIndex = 0;
- STR_VEC vt_result_files;
- if ( m_pvtnames == NULL)
- {
- STR_VEC::const_iterator it_name = vtnames.begin();
- for ( ; it_name != vtnames.end(); it_name++ )
- {
- STR_VEC::iterator it_file = m_pvtfiles->begin();
- for ( ; it_file != m_pvtfiles->end(); )
- {
- nIndex = it_file->find_last_of(_T('\\'));
- if (TString::npos != nIndex)
- {
- if (_tcsicmp(it_file->substr(nIndex + 1).c_str(), it_name->c_str()) == 0)
- {
- vt_result_files.push_back(*it_file);
- it_file = m_pvtfiles->erase(it_file);
- continue;
- }
- }
- it_file++;
- }
- }
- m_pvtfiles->clear();
- for ( STR_VEC::iterator it = vt_result_files.begin(); it != vt_result_files.end(); it++ )
- {
- m_pvtfiles->push_back(*it);
- }
- }
- else
- {
- if ( m_pvtnames->size() != m_pvtfiles->size() )
- return;
- STR_VEC::iterator it_name;
- STR_VEC::iterator it_file;
- STR_VEC vt_result_names;
- for ( STR_VEC::const_iterator it = vtnames.begin(); it != vtnames.end(); it++ )
- {
- it_name = m_pvtnames->begin();
- it_file = m_pvtfiles->begin();
- for ( ; it_file != m_pvtfiles->end(), it_name != m_pvtnames->end();)
- {
- if ( _tcsicmp(it_name->c_str(), it->c_str()) == 0 )
- {
- vt_result_files.push_back(*it_file);
- vt_result_names.push_back(*it_name);
- it_file = m_pvtfiles->erase(it_file);
- it_name = m_pvtnames->erase(it_name);
- continue;
- }
- it_file++;
- it_name++;
- }
- }
- m_pvtfiles->clear();
- m_pvtnames->clear();
- it_name = vt_result_names.begin();
- it_file = vt_result_files.begin();
- for ( ; it_file != vt_result_files.end(), it_name != vt_result_names.end(); it_file++, it_name++ )
- {
- m_pvtfiles->push_back(*it_file);
- m_pvtnames->push_back(*it_name);
- }
- }
- }
- void filehelpImpl::keepdowbyname(IN const STR_VEC &vtnames, IN STR_VEC &vtfiles)
- {
- if ( vtnames.size() == 0 )
- return;
- INT nIndex = 0;
- STR_VEC vt_result_files;
- STR_VEC::const_iterator it_name = vtnames.begin();
- for ( ; it_name != vtnames.end(); it_name++ )
- {
- STR_VEC::iterator it_file = vtfiles.begin();
- for ( ; it_file != vtfiles.end(); )
- {
- nIndex = it_file->find_last_of(_T('\\'));
- if (TString::npos != nIndex)
- {
- if (_tcsicmp(it_file->substr(nIndex + 1).c_str(), it_name->c_str()) == 0)
- {
- vt_result_files.push_back(*it_file);
- it_file = vtfiles.erase(it_file);
- continue;
- }
-
- }
- it_file++;
- }
- }
- vtfiles.clear();
- for ( STR_VEC::iterator it = vt_result_files.begin(); it != vt_result_files.end(); it++ )
- {
- vtfiles.push_back(*it);
- }
- }
- void filehelpImpl::keepdowbyname(IN const STR_VEC &vtnames, IN const STR_VEC &vtfiles, OUT STR_VEC &vt_result)
- {
- if ( vtnames.size() == 0 )
- return;
- INT nIndex = 0;
- STR_VEC::const_iterator it_name = vtnames.begin();
- for ( ; it_name != vtnames.end(); it_name++ )
- {
- STR_VEC::const_iterator it_file = vtfiles.begin();
- for ( ; it_file != vtfiles.end(); it_file++)
- {
- nIndex = it_file->find_last_of(_T('\\'));
- if (TString::npos != nIndex)
- {
- if (_tcsicmp(it_file->substr(nIndex + 1).c_str(), it_name->c_str()) == 0)
- {
- vt_result.push_back(*it_file);
- }
- }
- }
- }
- }
- void filehelpImpl::keepdowbyname_noext(IN const STR_VEC &vtnames)
- {
- if ( m_pvtfiles == NULL || m_pvtnames == &vtnames )
- return;
- INT nIndex = 0;
- STR_VEC vt_result_files;
- if ( m_pvtnames == NULL)
- {
- INT nIndex2 = 0;
- STR_VEC::const_iterator it_name = vtnames.begin();
- for ( ; it_name != vtnames.end(); it_name++ )
- {
- STR_VEC::iterator it_file = m_pvtfiles->begin();
- for ( ; it_file != m_pvtfiles->end(); )
- {
- nIndex = it_file->find_last_of(_T('\\'));
- nIndex2 = it_file->find_last_of(_T('.'));
- if (TString::npos != nIndex && TString::npos != nIndex2 && nIndex > nIndex2 )
- {
- if ( _tcsicmp(it_file->substr(nIndex+1,nIndex2 - nIndex - 1).c_str(), it_name->c_str()) == 0)
- {
- vt_result_files.push_back(*it_file);
- it_file = m_pvtfiles->erase(it_file);
- continue;
- }
- }
- it_file++;
- }
- }
- m_pvtfiles->clear();
- for ( STR_VEC::iterator it = vt_result_files.begin(); it != vt_result_files.end(); it++ )
- {
- m_pvtfiles->push_back(*it);
- }
- }
- else
- {
- if ( m_pvtnames->size() != m_pvtfiles->size() )
- return;
- STR_VEC::iterator it_name;
- STR_VEC::iterator it_file;
- STR_VEC vt_result_names;
- for ( STR_VEC::const_iterator it = vtnames.begin(); it != vtnames.end(); it++ )
- {
- it_name = m_pvtnames->begin();
- it_file = m_pvtfiles->begin();
- for ( ; it_file != m_pvtfiles->end(), it_name != m_pvtnames->end();)
- {
- if ( TString::npos != ( nIndex = it_name->find_last_of(_T('.'))))
- {
- if ( _tcsicmp(it_name->substr(0, nIndex).c_str(), it->c_str()) == 0 )
- {
- vt_result_files.push_back(*it_file);
- vt_result_names.push_back(*it_name);
- it_file = m_pvtfiles->erase(it_file);
- it_name = m_pvtnames->erase(it_name);
- continue;
- }
- }
- it_file++;
- it_name++;
- }
- }
- m_pvtfiles->clear();
- m_pvtnames->clear();
- it_name = vt_result_names.begin();
- it_file = vt_result_files.begin();
- for ( ; it_file != vt_result_files.end(), it_name != vt_result_names.end(); it_file++, it_name++ )
- {
- m_pvtfiles->push_back(*it_file);
- m_pvtnames->push_back(*it_name);
- }
- }
- }
- void filehelpImpl::keepdowbyname_noext(IN const STR_VEC &vtnames, IN STR_VEC &vtfiles)
- {
- if ( vtnames.size() == 0 )
- return;
- INT nIndex = 0;
- TString strName;
- STR_VEC vt_result_files;
- STR_VEC::const_iterator it_name = vtnames.begin();
- for ( ; it_name != vtnames.end(); it_name++ )
- {
- STR_VEC::iterator it_file = vtfiles.begin();
- for ( ; it_file != vtfiles.end(); )
- {
- nIndex = it_file->find_last_of(_T('\\'));
- if (TString::npos != nIndex)
- {
- strName = it_file->substr(nIndex+1);
- if ( TString::npos != ( nIndex = strName.find_last_of(_T('.'))))
- {
- if ( _tcsicmp(strName.substr(0,nIndex).c_str(), it_name->c_str()) == 0)
- {
- vt_result_files.push_back(*it_file);
- it_file = vtfiles.erase(it_file);
- continue;
- }
- }
- }
- it_file++;
- }
- }
- vtfiles.clear();
- for ( STR_VEC::iterator it = vt_result_files.begin(); it != vt_result_files.end(); it++ )
- {
- vtfiles.push_back(*it);
- }
- }
- void filehelpImpl::keepdowbyname_noext(IN const STR_VEC &vtnames, IN const STR_VEC &vtfiles, OUT STR_VEC &vt_result)
- {
- if ( vtnames.size() == 0 )
- return;
- INT nIndex = 0;
- TString strName;
- STR_VEC::const_iterator it_name = vtnames.begin();
- for ( ; it_name != vtnames.end(); it_name++ )
- {
- STR_VEC::const_iterator it_file = vtfiles.begin();
- for ( ; it_file != vtfiles.end(); it_file++)
- {
- nIndex = it_file->find_last_of(_T('\\'));
- if (TString::npos != nIndex)
- {
- strName = it_file->substr(nIndex+1);
- if ( TString::npos != ( nIndex = strName.find_last_of(_T('.'))))
- {
- if ( _tcsicmp(strName.substr(0,nIndex).c_str(), it_name->c_str()) == 0)
- {
- vt_result.push_back(*it_file);
- }
- }
- }
- }
- }
- }
- void filehelpImpl::subgroupExt(IN const TString &ext1, IN STR_VEC &vt1, IN const TString &ext2, IN STR_VEC &vt2)
- {
- // if (ext1.find(_T("*.*")) != TString::npos ) return;
- // if ( !iscorrectext(ext1) || vt1.size() == 0 ) return;
- //
- // // 获取复制扩展名;
- // int nIndex = 0;
- // TString strtmp;
- // TString strExt1(ext1);
- // strExt1.append(_T("|"));
- // STR_VEC vtExt1;
- //
- // // 将所有扩展名解析到数组里;
- // do
- // {
- // nIndex = strExt1.find(_T('|'));
- // if ( nIndex != TString::npos )
- // {
- // strtmp = strExt1.substr(0,nIndex);
- // strExt1 = strExt1.substr(nIndex+1);
- //
- // if(strtmp.compare(_T("*.*")))
- // vtExt1.push_back(strtmp);
- // }
- // } while ( strExt1.find(_T('|')) != TString::npos );
- }
- /************************************************************************/
- /* 函数:filterbyname[2/21/2017 Jeff];
- /* 描述:根据有后缀的文件名(如:001.jpg)来过虑文件;;
- /* 参数:;
- /* [IN] vtfiles:要被过滤的文件路径数组;
- /* [IN] vtnames:要过滤的文件名,每个文件名都有后缀,如:001.jpg;
- /* 返回:void;
- /* 注意:;
- /* 示例:;
- /*
- /* 修改:;
- /* 日期:;
- /* 内容:;
- /************************************************************************/
- void filehelpImpl::filterbyname(IN STR_VEC &vtfiles, IN const STR_VEC &vtnames)
- {// 再按名称过滤;
- INT nIndex = 0;
- TString strName;
- for ( STR_VEC::const_iterator it_name = vtnames.begin(); it_name != vtnames.end(); it_name++ )
- {
- for ( STR_VEC::iterator it_file = vtfiles.begin(); it_file != vtfiles.end(); )
- {
- nIndex = it_file->find_last_of(_T('\\'));
- if (TString::npos != nIndex)
- {
- strName = it_file->substr(nIndex+1);
- if ( _tcsicmp(strName.c_str(), it_name->c_str()) == 0 )
- {
- it_file = vtfiles.erase(it_file);
- continue;
- }
- }
- it_file++;
- }
- }
- }
- void filehelpImpl::filterbyname(IN const STR_VEC &vtnames)
- {
- if ( m_pvtfiles == NULL || m_pvtnames == &vtnames )
- return;
- INT nIndex = 0;
- TString strName;
- if ( m_pvtnames == NULL)
- {
- STR_VEC::const_iterator it_name = vtnames.begin();
- for ( ; it_name != vtnames.end(); it_name++ )
- {
- STR_VEC::iterator it_file = m_pvtfiles->begin();
- for ( ; it_file != m_pvtfiles->end(); )
- {
- nIndex = it_file->find_last_of(_T('\\'));
- if (TString::npos != nIndex)
- {
- strName = it_file->substr(nIndex+1);
- if ( _tcsicmp(strName.c_str(), it_name->c_str()) == 0)
- {
- it_file = m_pvtfiles->erase(it_file);
- continue;
- }
- }
- it_file++;
- }
- }
- }
- else
- {
- if ( m_pvtnames->size() != m_pvtfiles->size() )
- return;
- for ( STR_VEC::const_iterator it = vtnames.begin(); it != vtnames.end(); it++ )
- {
- STR_VEC::iterator it_name = m_pvtnames->begin();
- STR_VEC::iterator it_file = m_pvtfiles->begin();
- for ( ; it_file != m_pvtfiles->end(), it_name != m_pvtnames->end();)
- {
- if ( _tcsicmp(it_name->c_str(), it->c_str()) == 0 )
- {
- it_file = m_pvtfiles->erase(it_file);
- it_name = m_pvtnames->erase(it_name);
- continue;
- }
- it_file++;
- it_name++;
- }
- }
- }
- }
- // 根据无后缀的文件名(如:001)来过虑文件;
- void filehelpImpl::filterbyname_noext(IN STR_VEC &vtfiles, IN const STR_VEC &vtnames)
- {// 再按名称过滤;
- INT nIndex = 0;
- INT nIndex2 = 0;
- TString strName;
- for ( STR_VEC::iterator it_file = vtfiles.begin(); it_file != vtfiles.end(); )
- {
- nIndex = it_file->find_last_of(_T('\\'));
- nIndex2 = it_file->find_last_of(_T('.'));
- for ( STR_VEC::const_iterator it_name = vtnames.begin(); it_name != vtnames.end(); it_name++ )
- {
- if (TString::npos != nIndex && TString::npos != nIndex2 && nIndex2 > nIndex)
- {
- if ( _tcsicmp(it_file->substr(nIndex+1,nIndex2-nIndex-1).c_str(), it_name->c_str()) == 0)
- {
- it_file = vtfiles.erase(it_file);
- continue;
- }
- }
- it_file++;
- }
- }
- }
- void filehelpImpl::filterbyname_noext(IN const STR_VEC &vtnames)
- {
- if ( m_pvtfiles == NULL || m_pvtnames == &vtnames )
- return;
- INT nIndex = 0;
- TString strName;
- if ( m_pvtnames == NULL )
- {
- INT nIndex2 = 0;
- STR_VEC::iterator it_file = m_pvtfiles->begin();
- for ( ; it_file != m_pvtfiles->end(); )
- {
- nIndex = it_file->find_last_of(_T('\\'));
- nIndex2 = it_file->find_last_of(_T('.'));
- for ( STR_VEC::const_iterator it_name = vtnames.begin(); it_name != vtnames.end(); it_name++ )
- {
- if (TString::npos != nIndex && TString::npos != nIndex2 && nIndex2 > nIndex)
- {
- if ( _tcsicmp(it_file->substr(nIndex+1,nIndex2-nIndex-1).c_str(), it_name->c_str()) == 0 )
- {
- it_file = m_pvtfiles->erase(it_file);
- continue;
- }
- }
- it_file++;
- }
- }
- }
- else
- {
- if (m_pvtnames->size() != m_pvtfiles->size())
- return;
- for ( STR_VEC::const_iterator it = vtnames.begin(); it != vtnames.end(); it++ )
- {
- STR_VEC::iterator it_name = m_pvtnames->begin();
- STR_VEC::iterator it_file = m_pvtfiles->begin();
- for ( ; it_file != m_pvtfiles->end(), it_name != m_pvtnames->end();)
- {
- if ( TString::npos != (nIndex = it_name->find_last_of(_T('.'))) )
- {
- if ( _tcsicmp(it_name->substr(0, nIndex).c_str(), it->c_str()) == 0 )
- {
- it_file = m_pvtfiles->erase(it_file);
- it_name = m_pvtnames->erase(it_name);
- continue;
- }
- it_file++;
- it_name++;
- }
- }
- }
- }
- }
- //////////////////////////////////////////////////////////////////////////
- BOOL filehelpImpl::getall(IN LPCTSTR lpfolder, IN LPCTSTR lpfindext, IN OUT STR_VEC *pvtfiles, IN OUT STR_VEC *pvtnames, IN OUT STR_VEC *pvtfolders)
- {
- // 路径不存在;
- if (!PathFileExists(lpfolder))
- return FALSE;
- // 指针空;
- if (!pvtfiles || !pvtnames || !pvtfolders ) return FALSE;
- m_pvtfiles = pvtfiles;
- m_pvtnames = pvtnames;
- m_pvtfolders = pvtfolders;
- #if USE_IMGEXT
- // 判断扩展名有效性;
- if (!iscorrectext(lpfindext)) return FALSE;
- #endif
- findall(lpfolder);
- if ( _tcsstr(lpfindext, _T("*.*")) == NULL )
- {// 需要保留指定后缀;
- keepdownbyext(lpfindext, *pvtfiles);
- keepdownbyext(lpfindext, *pvtnames);
- }
- return TRUE;
- }
- BOOL filehelpImpl::getsubfolder(IN LPCTSTR lpfolder, IN STR_VEC *pvtfolders)
- {
- // 路径不存在;
- if (!PathFileExists(lpfolder))
- return FALSE;
- // 指针空;
- if (pvtfolders == NULL) return FALSE;
- m_pvtfolders = pvtfolders;
- findsubfolder(lpfolder);
- return TRUE;
- }
- BOOL filehelpImpl::getallsubfolder(IN LPCTSTR lpfolder, IN STR_VEC *pvtfolders)
- {
- // 路径不存在;
- if (!PathFileExists(lpfolder))
- return FALSE;
- // 指针空;
- if (pvtfolders == NULL) return FALSE;
- m_pvtfolders = pvtfolders;
- findallsubfolder(lpfolder);
- return TRUE;
- }
- //////////////////////////////////////////////////////////////////////////
- BOOL filehelpImpl::getfiles_findin_subfolder(IN LPCTSTR lpfolder, IN LPCTSTR lpfindext, IN STR_VEC *pvtfiles)
- {
- // 路径不存在;
- if (!PathFileExists(lpfolder))
- return FALSE;
- // 指针空;
- if (pvtfiles == NULL) return FALSE;
- m_pvtfiles = pvtfiles;
- #if USE_IMGEXT
- // 判断扩展名有效性;
- if (!iscorrectext(lpfindext)) return FALSE;
- #endif
- findfiles_findin_subfolder(lpfolder);
- if ( _tcsstr(lpfindext, _T("*.*")) == NULL )
- {// 需要保留指定后缀;
- keepdownbyext(lpfindext, *pvtfiles);
- }
- return TRUE;
- }
- BOOL filehelpImpl::getfiles_findout_subfolder(IN LPCTSTR lpfolder, IN LPCTSTR lpfindext, IN STR_VEC *pvtfiles)
- {
- // 路径不存在;
- if (!PathFileExists(lpfolder))
- return FALSE;
- // 指针空;
- if (pvtfiles == NULL) return FALSE;
- m_pvtfiles = pvtfiles;
- #if USE_IMGEXT
- // 判断扩展名有效性;
- if (!iscorrectext(lpfindext)) return FALSE;
- #endif
- findfiles_findout_subfolder(lpfolder);
- if ( _tcsstr(lpfindext, _T("*.*")) == NULL )
- {// 需要保留指定后缀;
- keepdownbyext(lpfindext, *pvtfiles);
- }
- return TRUE;
- }
- BOOL filehelpImpl::getfiles_within_subfolder(IN LPCTSTR lpfolder, IN LPCTSTR lpfindext, IN STR_VEC *pvtfiles, IN STR_VEC *pvtfolders)
- {
- // 路径不存在;
- if (!PathFileExists(lpfolder))
- return FALSE;
- // 指针空;
- if (pvtfiles == NULL) return FALSE;
- m_pvtfiles = pvtfiles;
- m_pvtfolders = pvtfolders;
- #if USE_IMGEXT
- // 判断扩展名有效性;
- if (!iscorrectext(lpfindext)) return FALSE;
- #endif
- findfiles_within_subfolder(lpfolder);
- if ( _tcsstr(lpfindext, _T("*.*")) == NULL )
- {// 需要保留指定后缀;
- keepdownbyext(lpfindext, *pvtfiles);
- }
- return TRUE;
- }
- //////////////////////////////////////////////////////////////////////////
- BOOL filehelpImpl::getfiles_bynames_findin_subfolder( IN LPCTSTR lpfolder, IN LPCTSTR lpfindext, IN STR_VEC &vtnames, IN STR_VEC *pvtfiles )
- {
- // 路径不存在;
- if (!PathFileExists(lpfolder))
- return FALSE;
- // 指针空;
- if (pvtfiles == NULL) return FALSE;
- m_pvtfiles = pvtfiles;
- #if USE_IMGEXT
- // 判断扩展名有效性;
- if (!iscorrectext(lpfindext)) return FALSE;
- #endif
- findfiles_findin_subfolder(lpfolder);
- if ( _tcsstr(lpfindext, _T("*.*")) == NULL )
- {// 需要保留指定后缀;
- keepdownbyext(lpfindext, *pvtfiles);
- }
- // 再按名称过滤;
- filterbyname(*pvtfiles, vtnames);
- return TRUE;
- }
- BOOL filehelpImpl::getfiles_bynames_findout_subfolder( IN LPCTSTR lpfolder, IN LPCTSTR lpfindext, IN STR_VEC &vtnames, IN OUT STR_VEC *pvtfiles )
- {
- // 路径不存在;
- if (!PathFileExists(lpfolder))
- return FALSE;
- // 指针空;
- if (pvtfiles == NULL) return FALSE;
- m_pvtfiles = pvtfiles;
- #if USE_IMGEXT
- // 判断扩展名有效性;
- if (!iscorrectext(lpfindext)) return FALSE;
- #endif
- findfiles_findout_subfolder(lpfolder);
- if ( _tcsstr(lpfindext, _T("*.*")) == NULL )
- {// 需要保留指定后缀;
- keepdownbyext(lpfindext, *pvtfiles);
- }
- // 再按名称过滤;
- filterbyname(*pvtfiles, vtnames);
- return TRUE;
- }
- BOOL filehelpImpl::getfiles_bynames_within_subfolder( IN LPCTSTR lpfolder, IN LPCTSTR lpfindext, IN STR_VEC &vtnames, IN STR_VEC *pvtfiles, IN STR_VEC *pvtfolders )
- {
- // 路径不存在;
- if (!PathFileExists(lpfolder))
- return FALSE;
- // 指针空;
- if (pvtfiles == NULL) return FALSE;
- m_pvtfiles = pvtfiles;
- m_pvtfolders = pvtfolders;
- #if USE_IMGEXT
- // 判断扩展名有效性;
- if (!iscorrectext(lpfindext)) return FALSE;
- #endif
- findfiles_within_subfolder(lpfolder);
- if ( _tcsstr(lpfindext, _T("*.*")) == NULL )
- {// 需要保留指定后缀;
- keepdownbyext(lpfindext, *pvtfiles);
- }
- // 再按名称过滤;
- filterbyname(*pvtfiles, vtnames);
- return TRUE;
- }
- //////////////////////////////////////////////////////////////////////////
- BOOL filehelpImpl::getnames_findin_subfolder(IN LPCTSTR lpfolder, IN LPCTSTR lpfindext, IN STR_VEC *pvtnames)
- {
- // 路径不存在;
- if (!PathFileExists(lpfolder))
- return FALSE;
- // 指针空;
- if (pvtnames == NULL) return FALSE;
- #if USE_IMGEXT
- // 判断扩展名有效性;
- if (!iscorrectext(lpfindext)) return FALSE;
- #endif
- m_pvtnames = pvtnames;
- findnames_findin_subfolder(lpfolder);
- if ( _tcsstr(lpfindext, _T("*.*")) == NULL )
- {// 需要保留指定后缀;
- keepdownbyext(lpfindext, *m_pvtnames);
- }
- return TRUE;
- }
- BOOL filehelpImpl::getnames_findout_subfolder(IN LPCTSTR lpfolder, IN LPCTSTR lpfindext, IN STR_VEC *pvtnames)
- {
- // 路径不存在;
- if (!PathFileExists(lpfolder))
- return FALSE;
- // 指针空;
- if (pvtnames == NULL) return FALSE;
- #if USE_IMGEXT
- // 判断扩展名有效性;
- if (!iscorrectext(lpfindext)) return FALSE;
- #endif
- m_pvtnames = pvtnames;
- findnames_findout_subfolder(lpfolder);
- if ( _tcsstr(lpfindext, _T("*.*")) == NULL )
- {// 需要保留指定后缀;
- keepdownbyext(lpfindext, *m_pvtnames);
- }
- return TRUE;
- }
- BOOL filehelpImpl::getnames_within_subfolder(IN LPCTSTR lpfolder, IN LPCTSTR lpfindext, IN STR_VEC *pvtnames, IN STR_VEC *pvtfolders)
- {
- // 路径不存在;
- if (!PathFileExists(lpfolder))
- return FALSE;
- // 指针空;
- if (pvtnames == NULL || pvtfolders == NULL )
- return FALSE;
- m_pvtfolders = pvtfolders;
- #if USE_IMGEXT
- // 判断扩展名有效性;
- if (!iscorrectext(lpfindext)) return FALSE;
- #endif
- m_pvtnames = pvtnames;
- m_pvtfolders = pvtfolders;
- findnames_within_subfolder(lpfolder);
- if ( _tcsstr(lpfindext, _T("*.*")) == NULL )
- {// 需要保留指定后缀;
- keepdownbyext(lpfindext, *m_pvtnames);
- }
- return TRUE;
- }
- //////////////////////////////////////////////////////////////////////////
- BOOL filehelpImpl::getfilesnames_findin_subfolder(IN LPCTSTR lpfolder, IN LPCTSTR lpfindext, IN STR_VEC *pvtfiles, IN STR_VEC *pvtnames)
- {
- // 路径不存在;
- if (!PathFileExists(lpfolder))
- return FALSE;
- // 指针空;
- if (pvtnames || !pvtnames) return FALSE;
- m_pvtfiles = pvtfiles;
- m_pvtnames = pvtnames;
- #if USE_IMGEXT
- // 判断扩展名有效性;
- if (!iscorrectext(lpfindext)) return FALSE;
- #endif
- findfilesnames_findin_subfolder(lpfolder);
- if ( _tcsstr(lpfindext, _T("*.*")) == NULL )
- {// 需要保留指定后缀;
- keepdownbyext(lpfindext, *pvtnames);
- keepdownbyext(lpfindext, *pvtfiles);
- }
- return TRUE;
- }
- BOOL filehelpImpl::getfilesnames_findout_subfolder(IN LPCTSTR lpfolder, IN LPCTSTR lpfindext, IN STR_VEC *pvtfiles, IN STR_VEC *pvtnames)
- {
- // 路径不存在;
- if (!PathFileExists(lpfolder))
- return FALSE;
- // 指针空;
- if (pvtnames || !pvtnames) return FALSE;
- m_pvtfiles = pvtfiles;
- m_pvtnames = pvtnames;
- #if USE_IMGEXT
- // 判断扩展名有效性;
- if (!iscorrectext(lpfindext)) return FALSE;
- #endif
- findfilesnames_findout_subfolder(lpfolder);
- if ( _tcsstr(lpfindext, _T("*.*")) == NULL )
- {// 需要保留指定后缀;
- keepdownbyext(lpfindext, *pvtnames);
- keepdownbyext(lpfindext, *pvtfiles);
- }
- return TRUE;
- }
- BOOL filehelpImpl::getfilesnames_within_subfolder(IN LPCTSTR lpfolder, IN LPCTSTR lpfindext, IN STR_VEC *pvtfiles, IN STR_VEC *pvtnames, IN STR_VEC *pvtfolders)
- {
- // 路径不存在;
- if (!PathFileExists(lpfolder))
- return FALSE;
- // 指针空;
- if (pvtnames || !pvtnames) return FALSE;
- m_pvtfiles = pvtfiles;
- m_pvtnames = pvtnames;
- m_pvtfolders = pvtfolders;
- #if USE_IMGEXT
- // 判断扩展名有效性;
- if (!iscorrectext(lpfindext)) return FALSE;
- #endif
- findfilesnames_within_subfolder(lpfolder);
- if ( _tcsstr(lpfindext, _T("*.*")) == NULL )
- {// 需要保留指定后缀;
- keepdownbyext(lpfindext, *pvtnames);
- keepdownbyext(lpfindext, *pvtfiles);
- }
- return TRUE;
- }
- #if 1
- //////////////////////////////////////////////////////////////////////////
- BOOL filehelpImpl::comparename_2file(IN LPCTSTR file1, IN LPCTSTR file2)
- {
- if (!file1 || !file2) return FALSE;
- if (!PathFileExists(file1) || !PathFileExists(file2))
- return FALSE;
- TString strfile1 = file1;
- TString strfile2 = file2;
- strfile1 = getfilename(strfile1);
- strfile2 = getfilename(strfile2);
- return !strfile1.compare(strfile2);
- }
- BOOL filehelpImpl::comparename_findin_names(IN LPCTSTR name)
- {
- if (!m_pvtnames || !name) return FALSE;
- for (STR_VEC::iterator it = m_pvtnames->begin(); it != m_pvtnames->end(); it++)
- {
- if ( _tcsicmp(name, it->c_str()) == 0)
- {
- // 打印日志,或提示用户同名文件路径在哪;
- return TRUE;
- }
- }
- return FALSE;
- }
- BOOL filehelpImpl::comparename_findin_names(IN LPCTSTR name, IN STR_VEC &vtnames)
- {
- if (!name) return FALSE;
- for (STR_VEC::iterator it = vtnames.begin(); it != vtnames.end(); it++)
- {
- if ( _tcsicmp(name, it->c_str()) == 0)
- {
- // 打印日志,或提示用户同名文件路径在哪;
- return TRUE;
- }
- }
- return FALSE;
- }
- BOOL filehelpImpl::comparename_findin_files(IN LPCTSTR name, IN STR_VEC &vtfiles)
- {
- if (!name) return FALSE;
- int nIndex = 0;
- for (STR_VEC::iterator it = vtfiles.begin(); it != vtfiles.end(); it++)
- {
- if ((nIndex = it->find_last_of(_T('\\'))) != TString::npos)
- {
- if (_tcsicmp(name, it->substr(nIndex+1).c_str()) == 0)
- {
- // 打印日志,或提示用户同名文件路径在哪;
- return TRUE;
- }
- }
- }
- return FALSE;
- }
- BOOL filehelpImpl::comparename_findin_folder(IN LPCTSTR name, IN LPCTSTR folder, IN LPCTSTR findext, IN BOOL bsubfolder)
- {
- #if USE_IMGEXT
- if (!name || !iscorrectext(findext)) return FALSE;
- #else
- if ( !name ) return FALSE;
- #endif
- STR_VEC vtnames;
- if (bsubfolder)
- {
- if (!getnames_findin_subfolder(folder, findext, &vtnames))
- return FALSE;
- }
- else
- {
- if (!getnames_findout_subfolder(folder, findext, &vtnames))
- return FALSE;
- }
- return comparename_findin_names(name, vtnames);
- }
- INT filehelpImpl::comparenames_findin_names(IN STR_VEC vtSrcnames, IN STR_VEC vtDesnames, OUT STR_VEC *pvtIsonym /* = NULL */)
- {
- if (vtSrcnames.size() == 0 || vtDesnames.size() == 0) return 0;
- INT nCount = 0;
- for (STR_VEC::iterator it1 = vtSrcnames.begin(); it1 != vtSrcnames.end(); it1++)
- {
- for (STR_VEC::iterator it2 = vtDesnames.begin(); it2 != vtDesnames.end(); it2++)
- {
- if (_tcsicmp(it1->c_str(), it2->c_str()) == 0)
- {
- nCount++;
- if (pvtIsonym)
- pvtIsonym->push_back(*it1);
- break;
- }
- }
- }
- return nCount;
- }
- INT filehelpImpl::comparenames_findin_files(IN STR_VEC vtnames, IN STR_VEC vtfiles, IN LPCTSTR findext, OUT STR_VEC *pvtIsonym /* = NULL */)
- {
- if (vtnames.size() == 0 || vtfiles.size() == 0) return 0;
- #if USE_IMGEXT
- if (!iscorrectext(findext)) return 0;
- #endif
- INT nCount = 0;
- for (STR_VEC::iterator it = vtnames.begin(); it != vtnames.end(); it++)
- {
- if (comparename_findin_files(it->c_str(), vtfiles))
- {
- if (pvtIsonym)
- pvtIsonym->push_back(*it);
- nCount++;
- }
- }
- return nCount;
- }
- INT filehelpImpl::comparenames_findin_folder(IN STR_VEC vtnames, IN LPCTSTR folder, IN BOOL bsubfolder, IN LPCTSTR findext, OUT STR_VEC *pvtIsonym /* = NULL */)
- {
- if (vtnames.size() == 0 || !PathFileExists(folder)) return 0;
- #if USE_IMGEXT
- if (!iscorrectext(findext)) return 0;
- #endif
- STR_VEC vtnames2;
- if (bsubfolder)
- {
- getnames_findin_subfolder(folder, findext, &vtnames2);
- }
- else
- {
- getnames_findout_subfolder(folder, findext, &vtnames2);
- }
- return comparenames_findin_names(vtnames, vtnames2, pvtIsonym);
- }
- //////////////////////////////////////////////////////////////////////////
- BOOL filehelpImpl::comparefile_findin_names(IN LPCTSTR file, IN STR_VEC& vtnames)
- {
- if (vtnames.size() == 0) return FALSE;
- if (!file || !PathFileExists(file)) return FALSE;
- TString strfile = file;
- TString name = getfilename(strfile);
- return comparename_findin_names(name.c_str(), vtnames);
- }
- BOOL filehelpImpl::comparefile_findin_files(IN LPCTSTR file, IN STR_VEC& vtfiles, IN LPCTSTR findext)
- {
- if (!file || !PathFileExists(file)) return FALSE;
- #if USE_IMGEXT
- if (!iscorrectext(findext)) return FALSE;
- #endif
- TString strfile = file;
- TString name = getfilename(strfile);
- // 过滤掉不需要的扩展名;
- keepdownbyext(findext, vtfiles);
- return comparename_findin_files(name.c_str(), vtfiles);
- }
- BOOL filehelpImpl::comparefile_findin_folder(IN LPCTSTR file, IN LPCTSTR folder, IN BOOL bsubfolder, IN LPCTSTR findext)
- {
- if (!file || !PathFileExists(file) || !folder || !PathFileExists(folder)) return FALSE;
- #if USE_IMGEXT
- if (!iscorrectext(findext)) return FALSE;
- #endif
- TString strfile = file;
- TString name = getfilename(strfile);
- STR_VEC vtnames;
- if (bsubfolder)
- {
- getnames_findin_subfolder(folder, findext, &vtnames);
- }
- else
- {
- getnames_findout_subfolder(folder, findext, &vtnames);
- }
- return comparename_findin_names(name.c_str(), vtnames);
- }
- INT filehelpImpl::comparefiles_findin_files(IN STR_VEC &vtfiles1, IN STR_VEC &vtfiles2, IN LPCTSTR findext, OUT STR_VEC *pvtIsonym /* = NULL */)
- {
- if (vtfiles1.size() == 0 || vtfiles2.size() == 0) return 0;
- #if USE_IMGEXT
- if (!iscorrectext(findext)) return 0;
- #endif
- // 过滤掉不需要的扩展名;
- keepdownbyext(findext, vtfiles1);
- // 过滤掉不需要的扩展名;
- keepdownbyext(findext, vtfiles2);
- INT nCount = 0;
- TString name;
- for (STR_VEC::iterator it = vtfiles1.begin(); it != vtfiles1.end(); it++)
- {
- name = getfilename(*it);
- if (comparename_findin_files(name.c_str(), vtfiles2))
- {
- if (pvtIsonym)
- pvtIsonym->push_back(name);
- nCount++;
- }
- }
- return nCount;
- }
- INT filehelpImpl::comparefiles_findin_folder(IN STR_VEC &vtfiles, IN LPCTSTR folder, IN BOOL bsubfolder, IN LPCTSTR findext, OUT STR_VEC *pvtIsonym /* = NULL */)
- {
- if (vtfiles.size() == 0 || !folder || !PathFileExists(folder)) return 0;
- #if USE_IMGEXT
- if (!iscorrectext(findext)) return 0;
- #endif
- STR_VEC vtnames;
- if (bsubfolder)
- {
- getnames_findin_subfolder(folder, findext, &vtnames);
- }
- else
- {
- getnames_findout_subfolder(folder, findext, &vtnames);
- }
- return comparenames_findin_files(vtnames, vtfiles, findext, pvtIsonym);
- }
- INT filehelpImpl::comparefolderself(IN LPCTSTR folder, IN LPCTSTR findext, OUT STR_VEC *pvtIsonym /* = NULL */)
- {
- OutputDebugString(_T("\n"));
- #if USE_IMGEXT
- if (!folder || !PathFileExists(folder) || !iscorrectext(findext)) return 0;
- #else
- if (!folder || !PathFileExists(folder) ) return 0;
- #endif
- STR_VEC vtsubfolders;
- vtsubfolders.push_back(folder); // 包含当前目录;
- getsubfolder(folder, &vtsubfolders);
- int n = vtsubfolders.size();
- STR_VEC *pvtfiles = new STR_VEC[n];
- for (STR_VEC::iterator it = vtsubfolders.begin(); it != vtsubfolders.end(); it++)
- {
- getfiles_findin_subfolder(it->c_str(), findext, &pvtfiles[--n]);
- }
- STR_VEC vtnames;
- n = vtsubfolders.size();
- TString name;
- for (int i = 0; i < n; i++)
- {
- for (STR_VEC::iterator it = pvtfiles[i].begin(); it != pvtfiles[i].end(); it++)
- {
- name = getfilename(*it);
- if (comparename_findin_names(name.c_str(), vtnames))
- {
- // 打印日志,提示客户重名的相片;
- OutputDebugString(it->c_str());
- OutputDebugString(_T("\n"));
- pvtIsonym->push_back(it->c_str());
- }
- else
- {
- vtnames.push_back(name);
- }
- }
- }
- if (pvtfiles)
- delete []pvtfiles;
- pvtfiles = NULL;
- return 0;
- }
- INT filehelpImpl::comparefolder_findin_folder(IN LPCTSTR folder1, IN LPCTSTR folder2, IN BOOL bsubfolder, IN LPCTSTR findext, OUT STR_VEC *pvtIsonym /* = NULL */)
- {
- return 0;
- }
- #endif
|