findfile.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877
  1. #include "StdAfx.h"
  2. #include "findfile.h"
  3. #include <algorithm>
  4. // 查找文件的最大数量限制在nMaxLimit;
  5. CONST size_t nMaxLimit = 0xFFFFFFFF; //--4294967295;
  6. // 查找文件的默认数量限制在nDefLimit;
  7. CONST size_t nDefLimit = 0xFFFFF; //--1048575
  8. // 路径分隔符;
  9. CONST TCHAR c_pathSeparator = _T('\\');
  10. CONST TString s_pathSeparator = _T("\\");
  11. CONST TString g_sVertical = _T("|");
  12. // 正确的扩展名及格式样列;
  13. // 这个值最好可以从配置文件ini或xml中获取,不用在代码里写死;
  14. CONST TString g_sCorrectExt = _T("*.jpg|*.jpeg|*.png|*.bmp|*.cr2|*.nef|*.raw");
  15. TString lowercase(IN const TString &Str)
  16. {
  17. #if 1 // 多字节生僻字下会出问题;
  18. TString sResult;
  19. for ( TString::const_iterator it = Str.begin(); it != Str.end(); it++ )
  20. {
  21. if ( *it < 0 )
  22. {// 小于0,含中文,什么都不做;
  23. sResult.append(1, *(it++));
  24. sResult.append(1, *it);
  25. }
  26. else
  27. {
  28. if (_T('A') <= *it && *it <= _T('Z'))
  29. sResult.append(1, *it + 32);
  30. else
  31. sResult.append(1, *it);
  32. }
  33. }
  34. return sResult;
  35. #else
  36. TString sResult;
  37. std::transform(Str.begin(), Str.end(), sResult.begin(), ::toupper);
  38. static CString str = _T("");
  39. str = Str.c_str();
  40. str.MakeLower();
  41. sResult = str.GetString();
  42. return sResult;
  43. #endif
  44. }
  45. TString uppercase(IN const TString &Str)
  46. {
  47. #if 1 // 多字节生僻字下会出问题;
  48. TString sResult;
  49. for ( TString::const_iterator it = Str.begin(); it != Str.end(); it++ )
  50. {
  51. if ( *it < 0 )
  52. {// 小于0,含中文,什么都不做;
  53. sResult.append(1, *(it++));
  54. sResult.append(1, *it);
  55. }
  56. else
  57. {
  58. if (_T('A') <= *it && *it <= _T('Z'))
  59. sResult.append(1, *it - 32);
  60. else
  61. sResult.append(1, *it);
  62. }
  63. }
  64. return sResult;
  65. #else
  66. TString sResult;
  67. static CString strTemp = _T("");
  68. strTemp = Str.c_str();
  69. strTemp.MakeUpper();
  70. sResult = strTemp.GetString();
  71. return sResult;
  72. #endif
  73. }
  74. TString getfilename(IN CONST TString &file)
  75. {
  76. TString name;
  77. TString strfile = file;
  78. int nIndex = strfile.find_last_of(_T('\\')); // 如果file不包含 '\\' ,得不到文件名;
  79. if (nIndex == TString::npos)
  80. {
  81. nIndex = strfile.find_last_of(_T('.'));
  82. if ( nIndex == TString::npos )
  83. return _T("");
  84. return strfile.substr(0, nIndex);
  85. }
  86. name = strfile.substr(nIndex+1);
  87. nIndex = name.find_last_of(_T('.'));
  88. if (nIndex == TString::npos)
  89. return _T("");
  90. return name.substr(0, nIndex);
  91. }
  92. // 判断指定字符串是否在数组里(不区分大小写);
  93. BOOL IsStringExistNoCase(IN CONST TString& str, IN STR_VEC &tagVt)
  94. {
  95. int nSize = tagVt.size();
  96. if (nSize == 0) return FALSE;
  97. BOOL bExist = FALSE;
  98. TString stmp1 = uppercase(str);
  99. TString stmp2;
  100. for (STR_VEC::iterator it = tagVt.begin(); it != tagVt.end(); it++)
  101. {
  102. stmp2 = uppercase(*it);
  103. if (stmp1.compare(stmp2) == 0)
  104. {
  105. bExist = TRUE;
  106. break;
  107. }
  108. }
  109. return bExist;
  110. }
  111. findfile::findfile(void):
  112. m_nlimit(nDefLimit),
  113. m_pvtfiles(NULL),
  114. m_pvtnames(NULL),
  115. m_pvtfolders(NULL),
  116. m_pvtfiles_sth(NULL),
  117. m_pvtfiles_mth(NULL)
  118. {
  119. groupExt();
  120. }
  121. findfile::~findfile(void)
  122. {
  123. }
  124. /************************************************************************/
  125. /* 函数:groupExt[2/19/2017 Jeff];
  126. /* 描述:将字符串后缀名按"|"符号分隔成数组;
  127. /* 参数:;
  128. /* [GBL] g_sCorrectExt:全局字符串;
  129. /* 返回:void;
  130. /* 注意:;
  131. /* 示例:;
  132. /*
  133. /* 修改:;
  134. /* 日期:;
  135. /* 内容:;
  136. /************************************************************************/
  137. void findfile::groupExt()
  138. {
  139. // 将所有扩展名解析到数组里;
  140. INT nIndex = 0;
  141. TString strtmp;
  142. TString strEffctExt = g_sCorrectExt;
  143. strEffctExt.append(_T("|"));
  144. do
  145. {
  146. nIndex = strEffctExt.find(_T('|'));
  147. if (nIndex != TString::npos)
  148. {
  149. strtmp = strEffctExt.substr(0, nIndex);
  150. strEffctExt = strEffctExt.substr(nIndex + 1);
  151. if (strtmp.compare(_T("*.*")) && strtmp.size())
  152. {
  153. if ( !IsStringExistNoCase(strtmp,m_vtEffctExt) )
  154. m_vtEffctExt.push_back(strtmp);
  155. }
  156. }
  157. } while (strEffctExt.find(_T('|')) != TString::npos);
  158. }
  159. /************************************************************************/
  160. /* 函数:[2/19/2017 Jeff];
  161. /* 描述:;
  162. /* 参数:;
  163. /* [IN] :;
  164. /* [OUT] :;
  165. /* [IN/OUT] :;
  166. /* 返回:void;
  167. /* 注意:;
  168. /* 示例:;
  169. /*
  170. /* 修改:;
  171. /* 日期:;
  172. /* 内容:;
  173. /************************************************************************/
  174. void findfile::groupExt( IN CONST TString &exts, IN STR_VEC &vtExts )
  175. {
  176. // 将所有扩展名解析到数组里;
  177. INT nIndex = 0;
  178. TString strtmp;
  179. TString strEffctExt = exts;
  180. strEffctExt.append(_T("|"));
  181. do
  182. {
  183. nIndex = strEffctExt.find(_T('|'));
  184. if (nIndex != TString::npos)
  185. {
  186. strtmp = strEffctExt.substr(0, nIndex);
  187. strEffctExt = strEffctExt.substr(nIndex + 1);
  188. if (strtmp.compare(_T("*.*")) && strtmp.size())
  189. {
  190. if ( !IsStringExistNoCase(strtmp,vtExts) )
  191. vtExts.push_back(strtmp);
  192. }
  193. }
  194. } while (strEffctExt.find(_T('|')) != TString::npos);
  195. }
  196. /************************************************************************/
  197. /* 函数:iscorrectext[2/18/2017 Jeff];
  198. /* 描述:判断指定的后缀串是否有效;
  199. /* 参数:;
  200. /* [IN] fext:输入的扩展名,fext的格式必须是:_T("*.jpg|*.jpeg|*.png|*.bmp");
  201. /* [IN] lpMistakenExt:不符合要求的扩展名;
  202. /* [IN/OUT] :;
  203. /* 返回:如果指定的扩展名符合要求,则返回TRUE,否则返回FALSE;
  204. /* 注意:
  205. /* 1.如果传入的扩展名包含_T("*.*"),则返回TRUE;若lpMistakenExt指针有效,记录第一次返回不符合要求的扩展名;
  206. /* 2.fext的格式必须是:_T("*.jpg|*.jpeg|*.png|*.bmp");
  207. /* 示例:;
  208. /*
  209. /* 修改:;
  210. /* 日期:;
  211. /* 内容:;
  212. /************************************************************************/
  213. BOOL findfile::iscorrectext(IN const TString &fext, OUT TString* lpMistakenExt /*= NULL*/)
  214. {
  215. if (fext.size() == 0) return FALSE;
  216. if (fext.find(_T("*.*")) != TString::npos) return TRUE;
  217. TString ext = lowercase(fext);
  218. if (ext[ext.length() - 1] != _T('|'))
  219. ext.append(g_sVertical);
  220. BOOL bret = TRUE;
  221. int nIndex = 0;
  222. do
  223. {
  224. nIndex = ext.find(_T('|'));
  225. if (nIndex != TString::npos)
  226. {
  227. if (g_sCorrectExt.find(ext.substr(0, nIndex)) == TString::npos)
  228. {
  229. if (lpMistakenExt)
  230. *lpMistakenExt = ext.substr(0, nIndex);
  231. bret = FALSE;
  232. break;
  233. }
  234. ext = ext.substr(nIndex + 1);
  235. }
  236. } while (ext.find(_T('|')) != TString::npos);
  237. return bret;
  238. }
  239. /************************************************************************/
  240. /* 函数:lowercase[2/18/2017 Jeff];
  241. /* 描述:将指定字符串小写化;
  242. /* 参数:;
  243. /* [IN] Str:要转为小写的字符串;
  244. /* [OUT] :;
  245. /* [IN/OUT] :;
  246. /* 返回:返回转小写后的字符串;
  247. /* 注意:;
  248. /* 示例:;
  249. /*
  250. /* 修改:;
  251. /* 日期:;
  252. /* 内容:;
  253. /************************************************************************/
  254. TString findfile::lowercase(IN const TString &Str)
  255. {
  256. TString sResult;
  257. for ( TString::const_iterator it = Str.begin(); it != Str.end(); it++ )
  258. {
  259. if ( *it < 0 )
  260. {// 小于0,含中文,什么都不做;
  261. sResult.append(1, *(it++));
  262. sResult.append(1, *it);
  263. }
  264. else
  265. {
  266. if (_T('A') <= *it && *it <= _T('Z'))
  267. sResult.append(1, *it + 32);
  268. else
  269. sResult.append(1, *it);
  270. }
  271. }
  272. return sResult;
  273. }
  274. void findfile::lowercase(IN TString& Str)
  275. {
  276. for ( TString::iterator it = Str.begin(); it != Str.end(); it++ )
  277. {
  278. if ( *it < 0 )
  279. {// 小于0,含中文,什么都不做;
  280. it++;
  281. }
  282. else
  283. {
  284. if (_T('A') <= *it && *it <= _T('Z'))
  285. *it += 32;
  286. }
  287. }
  288. }
  289. /************************************************************************/
  290. /* 函数:uppercase[2/18/2017 Jeff];
  291. /* 描述:将指定字符串大写化;
  292. /* 参数:;
  293. /* [IN] Str:要转为大写的字符串;
  294. /* [OUT] :;
  295. /* [IN/OUT] :;
  296. /* 返回:返回转大写后的字符串;
  297. /* 注意:;
  298. /* 示例:;
  299. /*
  300. /* 修改:;
  301. /* 日期:;
  302. /* 内容:;
  303. /************************************************************************/
  304. TString findfile::uppercase(IN const TString &Str)
  305. {
  306. TString sResult;
  307. for ( TString::const_iterator it = Str.begin(); it != Str.end(); it++ )
  308. {
  309. if ( *it < 0 )
  310. {// 小于0,含中文,什么都不做;
  311. sResult.append(1, *(it++));
  312. sResult.append(1, *it);
  313. }
  314. else
  315. {
  316. if (_T('a') <= *it && *it <= _T('z'))
  317. sResult.append(1, *it - 32);
  318. else
  319. sResult.append(1, *it);
  320. }
  321. }
  322. return sResult;
  323. }
  324. void findfile::uppercase(IN TString& Str)
  325. {
  326. for ( TString::iterator it = Str.begin(); it != Str.end(); it++ )
  327. {
  328. if ( *it < 0 )
  329. {// 小于0,含中文,什么都不做;
  330. it++;
  331. }
  332. else
  333. {
  334. if (_T('a') <= *it && *it <= _T('z'))
  335. *it -= 32;
  336. }
  337. }
  338. }
  339. /************************************************************************/
  340. /*
  341. 函数:match
  342. 描述:判断指定的文件命名是否匹配指定的扩展名;
  343. 参数:
  344. IN sFileExt 扩展名;
  345. IN sFile 文件名;
  346. 返回:匹配返回非0值,否则返回0;
  347. 注意:
  348. */
  349. /************************************************************************/
  350. void findfile::setlimit(IN CONST INT &nLimit)
  351. {
  352. if (nLimit < 1)
  353. m_nlimit = nDefLimit;
  354. if (nLimit < nMaxLimit)
  355. m_nlimit = nLimit;
  356. }
  357. // 获取文件名;
  358. TString findfile::getfilename(IN CONST TString &file)
  359. {
  360. TString name;
  361. TString strfile = file;
  362. int nIndex = strfile.find_last_of(_T('\\')); // 如果file不包含 '\\' ,得不到文件名;
  363. if (nIndex == TString::npos)
  364. {
  365. nIndex = strfile.find_last_of(_T('.'));
  366. if ( nIndex == TString::npos )
  367. return _T("");
  368. return strfile.substr(0, nIndex);
  369. }
  370. name = strfile.substr(nIndex+1);
  371. nIndex = name.find_last_of(_T('.'));
  372. if (nIndex == TString::npos)
  373. return _T("");
  374. return name.substr(0, nIndex);
  375. }
  376. // 全部;
  377. void findfile::findall(IN CONST TString& folder)
  378. {
  379. TString path = folder;
  380. if (path.size() > 0 && c_pathSeparator != path[path.size() - 1])
  381. path.append(s_pathSeparator);
  382. TString file = _T("*");
  383. TString s = path + file;
  384. WIN32_FIND_DATA fileinfo = { 0 };
  385. HANDLE handle = FindFirstFile(s.c_str(), &fileinfo);
  386. if (NULL != handle && INVALID_HANDLE_VALUE != handle)
  387. {
  388. do
  389. {
  390. // 检查是否超过最大数;
  391. if (checklimit()) break;
  392. // '.'和 '..'的系统文件去除;
  393. if (_T('.') != fileinfo.cFileName[0])
  394. {
  395. if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY) // 目录;
  396. {
  397. m_pvtfolders->push_back(path + fileinfo.cFileName);
  398. findall(path + fileinfo.cFileName);
  399. }
  400. else
  401. {
  402. if (!checklimit())
  403. {
  404. m_pvtnames->push_back(fileinfo.cFileName);
  405. m_pvtfiles->push_back(path + fileinfo.cFileName);
  406. }
  407. }
  408. }
  409. } while (FindNextFile(handle, &fileinfo));
  410. FindClose(handle);
  411. }
  412. }
  413. void findfile::findsubfolder(IN CONST TString& folder) // 查找子目录;
  414. {
  415. TString path = folder;
  416. if (path.size() > 0 && c_pathSeparator != path[path.size() - 1])
  417. path.append(s_pathSeparator);
  418. TString file = _T("*");
  419. TString s = path + file;
  420. WIN32_FIND_DATA fileinfo = { 0 };
  421. HANDLE handle = FindFirstFile(s.c_str(), &fileinfo);
  422. if (NULL != handle && INVALID_HANDLE_VALUE != handle)
  423. {
  424. do
  425. {
  426. if (_T('.') != fileinfo.cFileName[0])// '.'和 '..'的系统文件去除;
  427. {
  428. if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY) // 目录;
  429. {
  430. m_pvtfolders->push_back(path + fileinfo.cFileName);
  431. }
  432. }
  433. } while (FindNextFile(handle, &fileinfo));
  434. FindClose(handle);
  435. }
  436. }
  437. void findfile::findallsubfolder(IN CONST TString& folder)
  438. {
  439. TString path = folder;
  440. if (path.size() > 0 && c_pathSeparator != path[path.size() - 1])
  441. path.append(s_pathSeparator);
  442. TString file = _T("*");
  443. TString s = path + file;
  444. WIN32_FIND_DATA fileinfo = { 0 };
  445. HANDLE handle = FindFirstFile(s.c_str(), &fileinfo);
  446. if (NULL != handle && INVALID_HANDLE_VALUE != handle)
  447. {
  448. do
  449. {
  450. if (_T('.') != fileinfo.cFileName[0])// '.'和 '..'的系统文件去除;
  451. {
  452. if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY) // 目录;
  453. {
  454. m_pvtfolders->push_back(path + fileinfo.cFileName);
  455. findallsubfolder(path + fileinfo.cFileName); // 不入子目录查找;
  456. }
  457. }
  458. } while (FindNextFile(handle, &fileinfo));
  459. FindClose(handle);
  460. }
  461. }
  462. //////////////////////////////////////////////////////////////////////////
  463. void findfile::findfiles_findin_subfolder(IN CONST TString& folder)
  464. {
  465. TString path = folder;
  466. if (path.size() > 0 && c_pathSeparator != path[path.size() - 1])
  467. path.append(s_pathSeparator);
  468. TString file = _T("*");
  469. TString s = path + file;
  470. WIN32_FIND_DATA fileinfo = { 0 };
  471. HANDLE handle = FindFirstFile(s.c_str(), &fileinfo);
  472. if (NULL != handle && INVALID_HANDLE_VALUE != handle)
  473. {
  474. do
  475. {
  476. // 检查是否超过最大数;
  477. if (checklimit()) break;
  478. // '.'和 '..'的系统文件去除;
  479. if (_T('.') != fileinfo.cFileName[0])
  480. {
  481. if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY) // 目录;
  482. {
  483. findfiles_findin_subfolder(path + fileinfo.cFileName);
  484. }
  485. else
  486. {
  487. if (!checklimit())
  488. {
  489. m_pvtfiles->push_back(path + fileinfo.cFileName);
  490. }
  491. }
  492. }
  493. } while (FindNextFile(handle, &fileinfo));
  494. FindClose(handle);
  495. }
  496. }
  497. void findfile::findfiles_findout_subfolder(IN CONST TString& folder)
  498. {
  499. TString path = folder;
  500. if (path.size() > 0 && c_pathSeparator != path[path.size() - 1])
  501. path.append(s_pathSeparator);
  502. TString file = _T("*");
  503. TString s = path + file;
  504. WIN32_FIND_DATA fileinfo = { 0 };
  505. HANDLE handle = FindFirstFile(s.c_str(), &fileinfo);
  506. if (NULL != handle && INVALID_HANDLE_VALUE != handle)
  507. {
  508. do
  509. {
  510. // 检查是否超过最大数;
  511. if (checklimit()) break;
  512. // '.'和 '..'的系统文件去除;
  513. if (_T('.') != fileinfo.cFileName[0])
  514. {
  515. if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) != FILE_ATTRIBUTE_DIRECTORY) // 目录;
  516. {
  517. if (!checklimit())
  518. {
  519. m_pvtfiles->push_back(path + fileinfo.cFileName);
  520. }
  521. }
  522. }
  523. } while (FindNextFile(handle, &fileinfo));
  524. FindClose(handle);
  525. }
  526. }
  527. void findfile::findfiles_within_subfolder(IN CONST TString& folder)
  528. {
  529. TString path = folder;
  530. if (path.size() > 0 && c_pathSeparator != path[path.size() - 1])
  531. path.append(s_pathSeparator);
  532. TString file = _T("*");
  533. TString s = path + file;
  534. WIN32_FIND_DATA fileinfo = { 0 };
  535. HANDLE handle = FindFirstFile(s.c_str(), &fileinfo);
  536. if (NULL != handle && INVALID_HANDLE_VALUE != handle)
  537. {
  538. do
  539. {
  540. // 检查是否超过最大数;
  541. if (checklimit()) break;
  542. // '.'和 '..'的系统文件去除;
  543. if (_T('.') != fileinfo.cFileName[0])
  544. {
  545. if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY) // 目录;
  546. {
  547. m_pvtfolders->push_back(path + fileinfo.cFileName);
  548. findfiles_within_subfolder(path + fileinfo.cFileName);
  549. }
  550. else
  551. {
  552. if (!checklimit())
  553. {
  554. m_pvtfiles->push_back(path + fileinfo.cFileName);
  555. }
  556. }
  557. }
  558. } while (FindNextFile(handle, &fileinfo));
  559. FindClose(handle);
  560. }
  561. }
  562. //////////////////////////////////////////////////////////////////////////
  563. void findfile::findnames_findin_subfolder(IN CONST TString& folder)
  564. {
  565. TString path = folder;
  566. if (path.size() > 0 && c_pathSeparator != path[path.size() - 1])
  567. path.append(s_pathSeparator);
  568. TString file = _T("*");
  569. TString s = path + file;
  570. WIN32_FIND_DATA fileinfo = { 0 };
  571. HANDLE handle = FindFirstFile(s.c_str(), &fileinfo);
  572. if (NULL != handle && INVALID_HANDLE_VALUE != handle)
  573. {
  574. do
  575. {
  576. // 检查是否超过最大数;
  577. if (checklimit()) break;
  578. // '.'和 '..'的系统文件去除;
  579. if (_T('.') != fileinfo.cFileName[0])
  580. {
  581. if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY) // 目录;
  582. {
  583. findnames_findin_subfolder(path + fileinfo.cFileName);
  584. }
  585. else
  586. {
  587. if (!checklimit() )
  588. {
  589. m_pvtnames->push_back(fileinfo.cFileName);
  590. }
  591. }
  592. }
  593. } while (FindNextFile(handle, &fileinfo));
  594. FindClose(handle);
  595. }
  596. }
  597. void findfile::findnames_findout_subfolder(IN CONST TString& folder)
  598. {
  599. TString path = folder;
  600. if (path.size() > 0 && c_pathSeparator != path[path.size() - 1])
  601. path.append(s_pathSeparator);
  602. TString file = _T("*");
  603. TString s = path + file;
  604. WIN32_FIND_DATA fileinfo = { 0 };
  605. HANDLE handle = FindFirstFile(s.c_str(), &fileinfo);
  606. if (NULL != handle && INVALID_HANDLE_VALUE != handle)
  607. {
  608. do
  609. {
  610. // 检查是否超过最大数;
  611. if (checklimit()) break;
  612. // '.'和 '..'的系统文件去除;
  613. if (_T('.') != fileinfo.cFileName[0])
  614. {
  615. if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) != FILE_ATTRIBUTE_DIRECTORY) // 目录;
  616. {
  617. if (!checklimit())
  618. {
  619. m_pvtnames->push_back(fileinfo.cFileName);
  620. }
  621. }
  622. }
  623. } while (FindNextFile(handle, &fileinfo));
  624. FindClose(handle);
  625. }
  626. }
  627. void findfile::findnames_within_subfolder(IN CONST TString& folder)
  628. {
  629. TString path = folder;
  630. if (path.size() > 0 && c_pathSeparator != path[path.size() - 1])
  631. path.append(s_pathSeparator);
  632. TString file = _T("*");
  633. TString s = path + file;
  634. WIN32_FIND_DATA fileinfo = { 0 };
  635. HANDLE handle = FindFirstFile(s.c_str(), &fileinfo);
  636. if (NULL != handle && INVALID_HANDLE_VALUE != handle)
  637. {
  638. do
  639. {
  640. // 检查是否超过最大数;
  641. if (checklimit()) break;
  642. // '.'和 '..'的系统文件去除;
  643. if (_T('.') != fileinfo.cFileName[0])
  644. {
  645. if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY) // 目录;
  646. {
  647. m_pvtfolders->push_back(path + fileinfo.cFileName);
  648. findnames_within_subfolder(path + fileinfo.cFileName);
  649. }
  650. else
  651. {
  652. if (!checklimit())
  653. {
  654. m_pvtnames->push_back(fileinfo.cFileName);
  655. }
  656. }
  657. }
  658. } while (FindNextFile(handle, &fileinfo));
  659. FindClose(handle);
  660. }
  661. }
  662. //////////////////////////////////////////////////////////////////////////
  663. void findfile::findfilesnames_findin_subfolder(IN CONST TString& folder)
  664. {
  665. TString path = folder;
  666. if (path.size() > 0 && c_pathSeparator != path[path.size() - 1])
  667. path.append(s_pathSeparator);
  668. TString file = _T("*");
  669. TString s = path + file;
  670. WIN32_FIND_DATA fileinfo = { 0 };
  671. HANDLE handle = FindFirstFile(s.c_str(), &fileinfo);
  672. if (NULL != handle && INVALID_HANDLE_VALUE != handle)
  673. {
  674. do
  675. {
  676. // 检查是否超过最大数;
  677. if (checklimit()) break;
  678. // '.'和 '..'的系统文件去除;
  679. if (_T('.') != fileinfo.cFileName[0])
  680. {
  681. if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY) // 目录;
  682. {
  683. findfilesnames_findin_subfolder(path + fileinfo.cFileName);
  684. }
  685. else
  686. {
  687. if (!checklimit() )
  688. {
  689. m_pvtnames->push_back(fileinfo.cFileName);
  690. m_pvtfiles->push_back(path + fileinfo.cFileName);
  691. }
  692. }
  693. }
  694. } while (FindNextFile(handle, &fileinfo));
  695. FindClose(handle);
  696. }
  697. }
  698. void findfile::findfilesnames_findout_subfolder(IN CONST TString& folder)
  699. {
  700. TString path = folder;
  701. if (path.size() > 0 && c_pathSeparator != path[path.size() - 1])
  702. path.append(s_pathSeparator);
  703. TString file = _T("*");
  704. TString s = path + file;
  705. WIN32_FIND_DATA fileinfo = { 0 };
  706. HANDLE handle = FindFirstFile(s.c_str(), &fileinfo);
  707. if (NULL != handle && INVALID_HANDLE_VALUE != handle)
  708. {
  709. do
  710. {
  711. // 检查是否超过最大数;
  712. if (checklimit()) break;
  713. // '.'和 '..'的系统文件去除;
  714. if (_T('.') != fileinfo.cFileName[0])
  715. {
  716. if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) != FILE_ATTRIBUTE_DIRECTORY) // 目录;
  717. {
  718. if (!checklimit() )
  719. {
  720. m_pvtnames->push_back(fileinfo.cFileName);
  721. m_pvtfiles->push_back(path + fileinfo.cFileName);
  722. }
  723. }
  724. }
  725. } while (FindNextFile(handle, &fileinfo));
  726. FindClose(handle);
  727. }
  728. }
  729. void findfile::findfilesnames_within_subfolder(IN CONST TString& folder)
  730. {
  731. TString path = folder;
  732. if (path.size() > 0 && c_pathSeparator != path[path.size() - 1])
  733. path.append(s_pathSeparator);
  734. TString file = _T("*");
  735. TString s = path + file;
  736. WIN32_FIND_DATA fileinfo = { 0 };
  737. HANDLE handle = FindFirstFile(s.c_str(), &fileinfo);
  738. if (NULL != handle && INVALID_HANDLE_VALUE != handle)
  739. {
  740. do
  741. {
  742. // 检查是否超过最大数;
  743. if (checklimit()) break;
  744. // '.'和 '..'的系统文件去除;
  745. if (_T('.') != fileinfo.cFileName[0])
  746. {
  747. if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY) // 目录;
  748. {
  749. m_pvtfolders->push_back(path + fileinfo.cFileName);
  750. findfilesnames_within_subfolder(path + fileinfo.cFileName);
  751. }
  752. else
  753. {
  754. if (!checklimit() )
  755. {
  756. m_pvtnames->push_back(fileinfo.cFileName);
  757. m_pvtfiles->push_back(path + fileinfo.cFileName);
  758. }
  759. }
  760. }
  761. } while (FindNextFile(handle, &fileinfo));
  762. FindClose(handle);
  763. }
  764. }