findfile.cpp 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531
  1. #include "StdAfx.h"
  2. #include "findfile2.h"
  3. // 查找文件的最大数量限制在nMaxLimit;
  4. CONST UINT64 nMaxLimit = 0x100000; //--1048576
  5. // 查找文件的默认数量限制在nDefLimit;
  6. CONST UINT64 nDefLimit = 0x10000; //--65536
  7. // 正确的扩展名及格式样列;
  8. // 这个值最好可以从配置文件ini或xml中获取,不用在代码里写死;
  9. CONST CString g_strCorrectExt = _T("*.jpg|*.jpeg|*.png|*.bmp|*.cr2|*.nef|*.raw");
  10. findfile2::findfile2(void)
  11. {
  12. m_nlimit = nDefLimit;
  13. m_pfiles = NULL;
  14. m_pnames = NULL;
  15. m_pfolders = NULL;
  16. m_pnames_noext = NULL;
  17. m_pvtfiles_sth = NULL;
  18. m_pvtfiles_mth = NULL;
  19. groupExt();
  20. }
  21. findfile2::~findfile2(void)
  22. {
  23. }
  24. void findfile2::groupExt()
  25. {
  26. // 将所有扩展名解析到数组里;
  27. INT nIndex = 0;
  28. CString strtmp;
  29. CString strEffctExt = g_strCorrectExt;
  30. strEffctExt += _T("|");
  31. do
  32. {
  33. nIndex = strEffctExt.Find(_T('|'));
  34. if (nIndex != -1)
  35. {
  36. strtmp = strEffctExt.Left(nIndex);
  37. strEffctExt = strEffctExt.Mid(nIndex + 1);
  38. if (strtmp != _T("*.*"))
  39. m_vtEffctExt.Add(strtmp.Mid(1));
  40. }
  41. } while (strEffctExt.Find(_T('|')) != -1);
  42. }
  43. void findfile2::groupExt( IN CONST CString &strExts, IN CStringArray &AryExts )
  44. {
  45. // 将所有扩展名解析到数组里;
  46. INT nIndex = 0;
  47. CString strtmp;
  48. CString strEffctExt = strExts;
  49. strEffctExt += _T("|");
  50. do
  51. {
  52. nIndex = strEffctExt.Find(_T('|'));
  53. if (nIndex != -1)
  54. {
  55. strtmp = strEffctExt.Left(nIndex);
  56. strEffctExt = strEffctExt.Mid(nIndex + 1);
  57. if (strtmp != _T("*.*"))
  58. AryExts.Add(strtmp);
  59. }
  60. } while (strEffctExt.Find(_T('|')) != -1);
  61. }
  62. /************************************************************************/
  63. /*
  64. 函数:iscorrectext
  65. 描述:判断指定的后缀串是否有效;
  66. 参数:
  67. IN: fext 输入的扩展名:
  68. fext的格式必须是:_T("*.jpg|*.jpeg|*.png|*.bmp")
  69. IN lpMistakenExt 不符合要求的扩展名;
  70. 返回:如果指定的扩展名符合要求,则返回TRUE,否则返回FALSE;
  71. 注意:
  72. 1.如果传入的扩展名包含_T("*.*"),则返回TRUE;若lpMistakenExt指针有效,记录第一次返回不符合要求的扩展名;
  73. 2.fext的格式必须是:_T("*.jpg|*.jpeg|*.png|*.bmp")
  74. */
  75. /************************************************************************/
  76. BOOL findfile2::iscorrectext(IN const CString &fext, OUT CString* lpMistakenExt /*= NULL*/)
  77. {
  78. if (fext.IsEmpty()) return FALSE;
  79. if (fext.Find(_T("*.*")) != -1) return TRUE;
  80. CString ext = fext;
  81. ext.MakeLower();
  82. if (ext[ext.GetLength() - 1] != _T('|'))
  83. ext += _T("|");
  84. BOOL bret = TRUE;
  85. int nIndex = 0;
  86. do
  87. {
  88. nIndex = ext.Find(_T('|'));
  89. if (nIndex != -1)
  90. {
  91. if (g_strCorrectExt.Find(ext.Left(nIndex)) == -1)
  92. {
  93. if (lpMistakenExt)
  94. *lpMistakenExt = ext.Left(nIndex);
  95. bret = FALSE;
  96. break;
  97. }
  98. ext = ext.Mid(nIndex + 1);
  99. }
  100. } while (ext.Find(_T('|')) != -1);
  101. return bret;
  102. }
  103. /************************************************************************/
  104. /*
  105. 函数:match
  106. 描述:判断指定的文件命名是否匹配指定的扩展名;
  107. 参数:
  108. IN sFileExt 扩展名;
  109. IN sFile 文件名;
  110. 返回:匹配返回非0值,否则返回0;
  111. 注意:
  112. */
  113. /************************************************************************/
  114. int findfile2::match(IN CONST CString &sFileExt, IN CONST CString &sFile)
  115. {
  116. CString fext = sFileExt;
  117. CString file = sFile;
  118. fext.MakeLower();
  119. file.MakeLower();
  120. int pos = file.ReverseFind(_T('.'));
  121. if (-1 != pos)
  122. file = file.Mid(pos);
  123. return (-1 != fext.Find(file));
  124. }
  125. void findfile2::setlimit(IN CONST INT &nLimit)
  126. {
  127. if (nLimit < 1)
  128. m_nlimit = nDefLimit;
  129. if (nLimit < nMaxLimit)
  130. m_nlimit = nLimit;
  131. }
  132. // 保留指定的扩展名文件;
  133. void findfile2::keepdownext(IN CONST CString &keepExt, IN CStringArray &vtfiles)
  134. {
  135. if (keepExt.Find(_T("*.*")) != -1) return;
  136. if (!iscorrectext(keepExt) || vtfiles.GetSize() == 0) return;
  137. // 获取复制扩展名;
  138. int nIndex = 0;
  139. CString strtmp;
  140. CString strRemainExt(keepExt);
  141. strRemainExt += _T("|");
  142. CStringArray vtRemainExt;
  143. // 将所有扩展名解析到数组里;
  144. do
  145. {
  146. nIndex = strRemainExt.Find(_T('|'));
  147. if (nIndex != -1)
  148. {
  149. strtmp = strRemainExt.Left(nIndex);
  150. strRemainExt = strRemainExt.Mid(nIndex + 1);
  151. if (strtmp == _T("*.*"))
  152. vtRemainExt.Add(strtmp);
  153. }
  154. } while (strRemainExt.Find(_T('|')) != -1);
  155. // 过滤非复制扩展名的文件,同时去掉缩略图,保留指定复制扩展名的文件;
  156. INT nSize = vtfiles.GetSize();
  157. for (int i = nSize; i > 0; i--)
  158. {
  159. BOOL bExsit = FALSE;
  160. for (int n = 0; n < vtRemainExt.GetSize(); n++ )
  161. {
  162. if (match(vtRemainExt.ElementAt(n), vtfiles.ElementAt(i))) {
  163. bExsit = TRUE;
  164. break;
  165. }
  166. }
  167. if (!bExsit) {
  168. vtfiles.RemoveAt(i);
  169. continue;
  170. }
  171. }
  172. }
  173. // 移除指定扩展名的文件;
  174. void findfile2::keepoutext(IN CONST CString &removeext, IN CStringArray &vtfiles)
  175. {
  176. if (removeext.Find(_T("*.*")) != -1) return;
  177. if (!iscorrectext(removeext) || vtfiles.GetSize() == 0) return;
  178. // 获取复制扩展名;
  179. int nIndex = 0;
  180. CString strtmp;
  181. CString strRemoveExt(removeext);
  182. strRemoveExt += _T("|");
  183. CStringArray vtRemoveExt;
  184. // 将所有扩展名解析到数组里;
  185. do
  186. {
  187. nIndex = strRemoveExt.Find(_T('|'));
  188. if (nIndex != -1)
  189. {
  190. strtmp = strRemoveExt.Left(nIndex);
  191. strRemoveExt = strRemoveExt.Mid(nIndex + 1);
  192. if (strtmp == _T("*.*"))
  193. vtRemoveExt.Add(strtmp);
  194. }
  195. } while (strRemoveExt.Find(_T('|')) != -1);
  196. // 过滤非复制扩展名的文件,同时去掉缩略图,保留指定复制扩展名的文件;
  197. INT nSize = vtfiles.GetSize();
  198. for ( int i = nSize; i > 0; i-- )
  199. {
  200. for (int n = 0; n < vtRemoveExt.GetSize(); n++ )
  201. {
  202. if (match(vtRemoveExt.ElementAt(n), vtfiles.ElementAt(i))) {
  203. vtfiles.RemoveAt(i);
  204. break;
  205. }
  206. }
  207. }
  208. }
  209. void findfile2::subgroupExt(IN CONST CString &ext1, IN CStringArray &vt1, IN CONST CString &ext2, IN CStringArray &vt2)
  210. {
  211. // if (ext1.find(_T("*.*")) != CString::npos ) return;
  212. // if ( !iscorrectext(ext1) || vt1.size() == 0 ) return;
  213. //
  214. // // 获取复制扩展名;
  215. // int nIndex = 0;
  216. // CString strtmp;
  217. // CString strExt1(ext1);
  218. // strExt1.append(_T("|"));
  219. // CStringArray vtExt1;
  220. //
  221. // // 将所有扩展名解析到数组里;
  222. // do
  223. // {
  224. // nIndex = strExt1.find(_T('|'));
  225. // if ( nIndex != CString::npos )
  226. // {
  227. // strtmp = strExt1.substr(0,nIndex);
  228. // strExt1 = strExt1.substr(nIndex+1);
  229. //
  230. // if(strtmp.compare(_T("*.*")))
  231. // vtExt1.push_back(strtmp);
  232. // }
  233. // } while ( strExt1.find(_T('|')) != CString::npos );
  234. }
  235. // 获取文件名;
  236. CString findfile2::getfilename(IN CONST CString &file)
  237. {
  238. CString name;
  239. CString strfile = file;
  240. int nIndex = strfile.ReverseFind(_T('\\')); // 如果file不包含 '\\' ,得不到文件名;
  241. if (nIndex == -1)
  242. {
  243. nIndex = strfile.ReverseFind(_T('.'));
  244. if (nIndex == -1)
  245. return _T("");
  246. return strfile.Left(nIndex);
  247. }
  248. name = strfile.Mid(nIndex+1);
  249. nIndex = name.Find(_T('.'));
  250. if (nIndex == -1)
  251. return _T("");
  252. return name.Left(nIndex);
  253. }
  254. // 全部;
  255. void findfile2::findall(IN CONST CString& folder, IN CONST CString& findext)
  256. {
  257. CString path = folder;
  258. if (path.GetLength() > 0 && _T('\\') != path[path.GetLength() - 1])
  259. path += _T("\\");
  260. CString fext = findext;
  261. if (fext == _T("*") || fext == _T("*.*"))
  262. fext = _T("");
  263. CString file = _T("*");
  264. CString s = path + file;
  265. WIN32_FIND_DATA fileinfo = { 0 };
  266. HANDLE handle = FindFirstFile(s, &fileinfo);
  267. if (NULL != handle && INVALID_HANDLE_VALUE != handle)
  268. {
  269. do
  270. {
  271. // 检查是否超过最大数;
  272. if (checklimit()) break;
  273. // '.'和 '..'的系统文件去除;
  274. if (_T('.') != fileinfo.cFileName[0])
  275. {
  276. if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY) // 目录;
  277. {
  278. m_pfolders->Add(path + fileinfo.cFileName);
  279. findall(path + fileinfo.cFileName, fext);
  280. }
  281. else
  282. {
  283. if (!checklimit() && (0 == fext.GetLength() || match(fext, fileinfo.cFileName)))
  284. {
  285. m_pnames->Add(fileinfo.cFileName);
  286. m_pfiles->Add(path + fileinfo.cFileName);
  287. s = fileinfo.cFileName;
  288. file = s.Left(s.Find(_T('.')));
  289. m_pnames_noext->Add(file);
  290. }
  291. }
  292. }
  293. } while (FindNextFile(handle, &fileinfo));
  294. FindClose(handle);
  295. }
  296. }
  297. void findfile2::findsubfolder(IN CONST CString& folder)
  298. {
  299. CString path = folder;
  300. if (path.GetLength() > 0 && _T('\\') != path[path.GetLength() - 1])
  301. path += _T("\\");
  302. CString file = _T("*");
  303. CString s = path + file;
  304. WIN32_FIND_DATA fileinfo = { 0 };
  305. HANDLE handle = FindFirstFile(s, &fileinfo);
  306. if (NULL != handle && INVALID_HANDLE_VALUE != handle)
  307. {
  308. do
  309. {
  310. if (_T('.') != fileinfo.cFileName[0])// '.'和 '..'的系统文件去除;
  311. {
  312. if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY) // 目录;
  313. {
  314. m_pfolders->Add(path + fileinfo.cFileName);
  315. //findsubfolder(path+fileinfo.cFileName); // 不入子目录查找;
  316. }
  317. }
  318. } while (FindNextFile(handle, &fileinfo));
  319. FindClose(handle);
  320. }
  321. }
  322. void findfile2::findallsubfolder(IN CONST CString& folder)
  323. {
  324. CString path = folder;
  325. if (path.GetLength() > 0 && _T('\\') != path[path.GetLength() - 1])
  326. path += _T("\\");
  327. CString file = _T("*");
  328. CString s = path + file;
  329. WIN32_FIND_DATA fileinfo = { 0 };
  330. HANDLE handle = FindFirstFile(s, &fileinfo);
  331. if (NULL != handle && INVALID_HANDLE_VALUE != handle)
  332. {
  333. do
  334. {
  335. if (_T('.') != fileinfo.cFileName[0])// '.'和 '..'的系统文件去除;
  336. {
  337. if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY) // 目录;
  338. {
  339. m_pfolders->Add(path + fileinfo.cFileName);
  340. findsubfolder(path + fileinfo.cFileName); // 不入子目录查找;
  341. }
  342. }
  343. } while (FindNextFile(handle, &fileinfo));
  344. FindClose(handle);
  345. }
  346. }
  347. //////////////////////////////////////////////////////////////////////////
  348. void findfile2::findfiles_findin_subfolder(IN CONST CString& folder, IN CONST CString& findext)
  349. {
  350. CString path = folder;
  351. if (path.GetLength() > 0 && _T('\\') != path[path.GetLength() - 1])
  352. path += _T("\\");
  353. CString fext = findext;
  354. if (fext == _T("*") || fext == _T("*.*"))
  355. fext = _T("");
  356. CString file = _T("*");
  357. CString s = path + file;
  358. WIN32_FIND_DATA fileinfo = { 0 };
  359. HANDLE handle = FindFirstFile(s, &fileinfo);
  360. if (NULL != handle && INVALID_HANDLE_VALUE != handle)
  361. {
  362. do
  363. {
  364. // 检查是否超过最大数;
  365. if (checklimit()) break;
  366. // '.'和 '..'的系统文件去除;
  367. if (_T('.') != fileinfo.cFileName[0])
  368. {
  369. if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY) // 目录;
  370. {
  371. findfiles_findin_subfolder(path + fileinfo.cFileName, fext);
  372. }
  373. else
  374. {
  375. if (!checklimit() && (0 == fext.GetLength() || match(fext, fileinfo.cFileName)))
  376. {
  377. m_pfiles->Add(path + fileinfo.cFileName);
  378. }
  379. }
  380. }
  381. } while (FindNextFile(handle, &fileinfo));
  382. FindClose(handle);
  383. }
  384. }
  385. void findfile2::findfiles_findout_subfolder(IN CONST CString& folder, IN CONST CString& findext)
  386. {
  387. CString path = folder;
  388. if (path.GetLength() > 0 && _T('\\') != path[path.GetLength() - 1])
  389. path += _T("\\");
  390. CString fext = findext;
  391. if (fext == _T("*") || fext == _T("*.*"))
  392. fext = _T("");
  393. CString file = _T("*");
  394. CString s = path + file;
  395. WIN32_FIND_DATA fileinfo = { 0 };
  396. HANDLE handle = FindFirstFile(s, &fileinfo);
  397. if (NULL != handle && INVALID_HANDLE_VALUE != handle)
  398. {
  399. do
  400. {
  401. // 检查是否超过最大数;
  402. if (checklimit()) break;
  403. // '.'和 '..'的系统文件去除;
  404. if (_T('.') != fileinfo.cFileName[0])
  405. {
  406. if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) != FILE_ATTRIBUTE_DIRECTORY) // 目录;
  407. {
  408. if (!checklimit() && (0 == fext.GetLength() || match(fext, fileinfo.cFileName)))
  409. {
  410. m_pfiles->Add(path + fileinfo.cFileName);
  411. }
  412. }
  413. }
  414. } while (FindNextFile(handle, &fileinfo));
  415. FindClose(handle);
  416. }
  417. }
  418. void findfile2::findfiles_within_subfolder(IN CONST CString& folder, IN CONST CString& findext)
  419. {
  420. CString path = folder;
  421. if (path.GetLength() > 0 && _T('\\') != path[path.GetLength() - 1])
  422. path += _T("\\");
  423. CString fext = findext;
  424. if (fext == _T("*") || fext == _T("*.*"))
  425. fext = _T("");
  426. CString file = _T("*");
  427. CString s = path + file;
  428. WIN32_FIND_DATA fileinfo = { 0 };
  429. HANDLE handle = FindFirstFile(s, &fileinfo);
  430. if (NULL != handle && INVALID_HANDLE_VALUE != handle)
  431. {
  432. do
  433. {
  434. // 检查是否超过最大数;
  435. if (checklimit()) break;
  436. // '.'和 '..'的系统文件去除;
  437. if (_T('.') != fileinfo.cFileName[0])
  438. {
  439. if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY) // 目录;
  440. {
  441. m_pfolders->Add(path + fileinfo.cFileName);
  442. findfiles_within_subfolder(path + fileinfo.cFileName, fext);
  443. }
  444. else
  445. {
  446. if (!checklimit() && (0 == fext.GetLength() || match(fext, fileinfo.cFileName)))
  447. {
  448. m_pfiles->Add(path + fileinfo.cFileName);
  449. }
  450. }
  451. }
  452. } while (FindNextFile(handle, &fileinfo));
  453. FindClose(handle);
  454. }
  455. }
  456. //////////////////////////////////////////////////////////////////////////
  457. void findfile2::findnames_findin_subfolder(IN CONST CString& folder, IN CONST CString& findext)
  458. {
  459. CString path = folder;
  460. if (path.GetLength() > 0 && _T('\\') != path[path.GetLength() - 1])
  461. path += _T("\\");
  462. CString fext = findext;
  463. if (fext == _T("*") || fext == _T("*.*"))
  464. fext = _T("");
  465. CString file = _T("*");
  466. CString s = path + file;
  467. WIN32_FIND_DATA fileinfo = { 0 };
  468. HANDLE handle = FindFirstFile(s, &fileinfo);
  469. if (NULL != handle && INVALID_HANDLE_VALUE != handle)
  470. {
  471. do
  472. {
  473. // 检查是否超过最大数;
  474. if (checklimit()) break;
  475. // '.'和 '..'的系统文件去除;
  476. if (_T('.') != fileinfo.cFileName[0])
  477. {
  478. if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY) // 目录;
  479. {
  480. findnames_findin_subfolder(path + fileinfo.cFileName, fext);
  481. }
  482. else
  483. {
  484. if (!checklimit() && (0 == fext.GetLength() || match(fext, fileinfo.cFileName)))
  485. {
  486. m_pnames->Add(fileinfo.cFileName);
  487. }
  488. }
  489. }
  490. } while (FindNextFile(handle, &fileinfo));
  491. FindClose(handle);
  492. }
  493. }
  494. void findfile2::findnames_findout_subfolder(IN CONST CString& folder, IN CONST CString& findext)
  495. {
  496. CString path = folder;
  497. if (path.GetLength() > 0 && _T('\\') != path[path.GetLength() - 1])
  498. path += _T("\\");
  499. CString fext = findext;
  500. if (fext == _T("*") || fext == _T("*.*"))
  501. fext = _T("");
  502. CString file = _T("*");
  503. CString s = path + file;
  504. WIN32_FIND_DATA fileinfo = { 0 };
  505. HANDLE handle = FindFirstFile(s, &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() && (0 == fext.GetLength() || match(fext, fileinfo.cFileName)))
  518. {
  519. m_pnames->Add(fileinfo.cFileName);
  520. }
  521. }
  522. }
  523. } while (FindNextFile(handle, &fileinfo));
  524. FindClose(handle);
  525. }
  526. }
  527. void findfile2::findnames_within_subfolder(IN CONST CString& folder, IN CONST CString& findext)
  528. {
  529. CString path = folder;
  530. if (path.GetLength() > 0 && _T('\\') != path[path.GetLength() - 1])
  531. path += _T("\\");
  532. CString fext = findext;
  533. if (fext == _T("*") || fext == _T("*.*"))
  534. fext = _T("");
  535. CString file = _T("*");
  536. CString s = path + file;
  537. WIN32_FIND_DATA fileinfo = { 0 };
  538. HANDLE handle = FindFirstFile(s, &fileinfo);
  539. if (NULL != handle && INVALID_HANDLE_VALUE != handle)
  540. {
  541. do
  542. {
  543. // 检查是否超过最大数;
  544. if (checklimit()) break;
  545. // '.'和 '..'的系统文件去除;
  546. if (_T('.') != fileinfo.cFileName[0])
  547. {
  548. if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY) // 目录;
  549. {
  550. m_pfolders->Add(path + fileinfo.cFileName);
  551. findnames_within_subfolder(path + fileinfo.cFileName, fext);
  552. }
  553. else
  554. {
  555. if (!checklimit() && (0 == fext.GetLength() || match(fext, fileinfo.cFileName)))
  556. {
  557. m_pnames->Add(fileinfo.cFileName);
  558. }
  559. }
  560. }
  561. } while (FindNextFile(handle, &fileinfo));
  562. FindClose(handle);
  563. }
  564. }
  565. //////////////////////////////////////////////////////////////////////////
  566. void findfile2::findnames_findin_subfolder_ex(IN CONST CString& folder, IN CONST CString& findext)
  567. {
  568. CString path = folder;
  569. if (path.GetLength() > 0 && _T('\\') != path[path.GetLength() - 1])
  570. path += _T("\\");
  571. CString fext = findext;
  572. if (fext == _T("*") || fext == _T("*.*"))
  573. fext = _T("");
  574. CString file = _T("*");
  575. CString s = path + file;
  576. WIN32_FIND_DATA fileinfo = { 0 };
  577. HANDLE handle = FindFirstFile(s, &fileinfo);
  578. if (NULL != handle && INVALID_HANDLE_VALUE != handle)
  579. {
  580. do
  581. {
  582. // 检查是否超过最大数;
  583. if (checklimit()) break;
  584. // '.'和 '..'的系统文件去除;
  585. if (_T('.') != fileinfo.cFileName[0])
  586. {
  587. if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY) // 目录;
  588. {
  589. findnames_findin_subfolder(path + fileinfo.cFileName, fext);
  590. }
  591. else
  592. {
  593. if (!checklimit() && (0 == fext.GetLength() || match(fext, fileinfo.cFileName)))
  594. {
  595. s = fileinfo.cFileName;
  596. file = s.Left(s.ReverseFind(_T('.')));
  597. m_pnames_noext->Add(file);
  598. }
  599. }
  600. }
  601. } while (FindNextFile(handle, &fileinfo));
  602. FindClose(handle);
  603. }
  604. }
  605. void findfile2::findnames_findout_subfolder_ex(IN CONST CString& folder, IN CONST CString& findext)
  606. {
  607. CString path = folder;
  608. if (path.GetLength() > 0 && _T('\\') != path[path.GetLength() - 1])
  609. path += _T("\\");
  610. CString fext = findext;
  611. if (fext == _T("*") || fext == _T("*.*"))
  612. fext = _T("");
  613. CString file = _T("*");
  614. CString s = path + file;
  615. WIN32_FIND_DATA fileinfo = { 0 };
  616. HANDLE handle = FindFirstFile(s, &fileinfo);
  617. if (NULL != handle && INVALID_HANDLE_VALUE != handle)
  618. {
  619. do
  620. {
  621. // 检查是否超过最大数;
  622. if (checklimit()) break;
  623. // '.'和 '..'的系统文件去除;
  624. if (_T('.') != fileinfo.cFileName[0])
  625. {
  626. if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) != FILE_ATTRIBUTE_DIRECTORY) // 目录;
  627. {
  628. if (!checklimit() && (0 == fext.GetLength() || match(fext, fileinfo.cFileName)))
  629. {
  630. s = fileinfo.cFileName;
  631. file = s.Left(s.ReverseFind(_T('.')));
  632. m_pnames_noext->Add(file);
  633. }
  634. }
  635. }
  636. } while (FindNextFile(handle, &fileinfo));
  637. FindClose(handle);
  638. }
  639. }
  640. void findfile2::findnames_within_subfolder_ex(IN CONST CString& folder, IN CONST CString& findext)
  641. {
  642. CString path = folder;
  643. if (path.GetLength() > 0 && _T('\\') != path[path.GetLength() - 1])
  644. path += _T("\\");
  645. CString fext = findext;
  646. if (fext == _T("*") || fext == _T("*.*"))
  647. fext = _T("");
  648. CString file = _T("*");
  649. CString s = path + file;
  650. WIN32_FIND_DATA fileinfo = { 0 };
  651. HANDLE handle = FindFirstFile(s, &fileinfo);
  652. if (NULL != handle && INVALID_HANDLE_VALUE != handle)
  653. {
  654. do
  655. {
  656. // 检查是否超过最大数;
  657. if (checklimit()) break;
  658. // '.'和 '..'的系统文件去除;
  659. if (_T('.') != fileinfo.cFileName[0])
  660. {
  661. if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY) // 目录;
  662. {
  663. m_pfolders->Add(path + fileinfo.cFileName);
  664. findnames_within_subfolder(path + fileinfo.cFileName, fext);
  665. }
  666. else
  667. {
  668. if (!checklimit() && (0 == fext.GetLength() || match(fext, fileinfo.cFileName)))
  669. {
  670. s = fileinfo.cFileName;
  671. file = s.Left( s.ReverseFind(_T('.')));
  672. m_pnames_noext->Add(file);
  673. }
  674. }
  675. }
  676. } while (FindNextFile(handle, &fileinfo));
  677. FindClose(handle);
  678. }
  679. }
  680. //////////////////////////////////////////////////////////////////////////
  681. void findfile2::findfilesnames_findin_subfolder(IN CONST CString& folder, IN CONST CString& findext)
  682. {
  683. CString path = folder;
  684. if (path.GetLength() > 0 && _T('\\') != path[path.GetLength() - 1])
  685. path += _T("\\");
  686. CString fext = findext;
  687. if (fext == _T("*") || fext == _T("*.*"))
  688. fext = _T("");
  689. CString file = _T("*");
  690. CString s = path + file;
  691. WIN32_FIND_DATA fileinfo = { 0 };
  692. HANDLE handle = FindFirstFile(s, &fileinfo);
  693. if (NULL != handle && INVALID_HANDLE_VALUE != handle)
  694. {
  695. do
  696. {
  697. // 检查是否超过最大数;
  698. if (checklimit()) break;
  699. // '.'和 '..'的系统文件去除;
  700. if (_T('.') != fileinfo.cFileName[0])
  701. {
  702. if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY) // 目录;
  703. {
  704. findfilesnames_findin_subfolder(path + fileinfo.cFileName, fext);
  705. }
  706. else
  707. {
  708. if (!checklimit() && (0 == fext.GetLength() || match(fext, fileinfo.cFileName)))
  709. {
  710. m_pnames->Add(fileinfo.cFileName);
  711. m_pfiles->Add(path + fileinfo.cFileName);
  712. }
  713. }
  714. }
  715. } while (FindNextFile(handle, &fileinfo));
  716. FindClose(handle);
  717. }
  718. }
  719. void findfile2::findfilesnames_findout_subfolder(IN CONST CString& folder, IN CONST CString& findext)
  720. {
  721. CString path = folder;
  722. if (path.GetLength() > 0 && _T('\\') != path[path.GetLength() - 1])
  723. path += _T("\\");
  724. CString fext = findext;
  725. if (fext == _T("*") || fext == _T("*.*"))
  726. fext = _T("");
  727. CString file = _T("*");
  728. CString s = path + file;
  729. WIN32_FIND_DATA fileinfo = { 0 };
  730. HANDLE handle = FindFirstFile(s, &fileinfo);
  731. if (NULL != handle && INVALID_HANDLE_VALUE != handle)
  732. {
  733. do
  734. {
  735. // 检查是否超过最大数;
  736. if (checklimit()) break;
  737. // '.'和 '..'的系统文件去除;
  738. if (_T('.') != fileinfo.cFileName[0])
  739. {
  740. if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) != FILE_ATTRIBUTE_DIRECTORY) // 目录;
  741. {
  742. if (!checklimit() && (0 == fext.GetLength() || match(fext, fileinfo.cFileName)))
  743. {
  744. m_pnames->Add(fileinfo.cFileName);
  745. m_pfiles->Add(path + fileinfo.cFileName);
  746. }
  747. }
  748. }
  749. } while (FindNextFile(handle, &fileinfo));
  750. FindClose(handle);
  751. }
  752. }
  753. void findfile2::findfilesnames_within_subfolder(IN CONST CString& folder, IN CONST CString& findext)
  754. {
  755. CString path = folder;
  756. if (path.GetLength() > 0 && _T('\\') != path[path.GetLength() - 1])
  757. path += _T("\\");
  758. CString fext = findext;
  759. if (fext == _T("*") || fext == _T("*.*"))
  760. fext = _T("");
  761. CString file = _T("*");
  762. CString s = path + file;
  763. WIN32_FIND_DATA fileinfo = { 0 };
  764. HANDLE handle = FindFirstFile(s, &fileinfo);
  765. if (NULL != handle && INVALID_HANDLE_VALUE != handle)
  766. {
  767. do
  768. {
  769. // 检查是否超过最大数;
  770. if (checklimit()) break;
  771. // '.'和 '..'的系统文件去除;
  772. if (_T('.') != fileinfo.cFileName[0])
  773. {
  774. if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY) // 目录;
  775. {
  776. m_pfolders->Add(fileinfo.cFileName);
  777. findfilesnames_within_subfolder(path + fileinfo.cFileName, fext);
  778. }
  779. else
  780. {
  781. if (!checklimit() && (0 == fext.GetLength() || match(fext, fileinfo.cFileName)))
  782. {
  783. m_pnames->Add(fileinfo.cFileName);
  784. m_pfiles->Add(path + fileinfo.cFileName);
  785. }
  786. }
  787. }
  788. } while (FindNextFile(handle, &fileinfo));
  789. FindClose(handle);
  790. }
  791. }
  792. void findfile2::findfilesnames_findin_subfolder_ex(IN CONST CString& folder, IN CONST CString& findext)
  793. {
  794. CString path = folder;
  795. if (path.GetLength() > 0 && _T('\\') != path[path.GetLength() - 1])
  796. path += _T("\\");
  797. CString fext = findext;
  798. if (fext == _T("*") || fext == _T("*.*"))
  799. fext = _T("");
  800. CString file = _T("*");
  801. CString s = path + file;
  802. WIN32_FIND_DATA fileinfo = { 0 };
  803. HANDLE handle = FindFirstFile(s, &fileinfo);
  804. if (NULL != handle && INVALID_HANDLE_VALUE != handle)
  805. {
  806. do
  807. {
  808. // 检查是否超过最大数;
  809. if (checklimit()) break;
  810. // '.'和 '..'的系统文件去除;
  811. if (_T('.') != fileinfo.cFileName[0])
  812. {
  813. if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY) // 目录;
  814. {
  815. findfilesnames_findin_subfolder(path + fileinfo.cFileName, fext);
  816. }
  817. else
  818. {
  819. if (!checklimit() && (0 == fext.GetLength() || match(fext, fileinfo.cFileName)))
  820. {
  821. m_pfiles->Add(path + fileinfo.cFileName);
  822. s = fileinfo.cFileName;
  823. file = s.Left( s.ReverseFind(_T('.')));
  824. m_pnames_noext->Add(file);
  825. }
  826. }
  827. }
  828. } while (FindNextFile(handle, &fileinfo));
  829. FindClose(handle);
  830. }
  831. }
  832. void findfile2::findfilesnames_findout_subfolder_ex(IN CONST CString& folder, IN CONST CString& findext)
  833. {
  834. CString path = folder;
  835. if (path.GetLength() > 0 && _T('\\') != path[path.GetLength() - 1])
  836. path += _T("\\");
  837. CString fext = findext;
  838. if (fext == _T("*") || fext == _T("*.*"))
  839. fext = _T("");
  840. CString file = _T("*");
  841. CString s = path + file;
  842. WIN32_FIND_DATA fileinfo = { 0 };
  843. HANDLE handle = FindFirstFile(s, &fileinfo);
  844. if (NULL != handle && INVALID_HANDLE_VALUE != handle)
  845. {
  846. do
  847. {
  848. // 检查是否超过最大数;
  849. if (checklimit()) break;
  850. // '.'和 '..'的系统文件去除;
  851. if (_T('.') != fileinfo.cFileName[0])
  852. {
  853. if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY) // 目录;
  854. {
  855. findfilesnames_findout_subfolder_ex(path + fileinfo.cFileName, fext);
  856. }
  857. else
  858. {
  859. if (!checklimit() && (0 == fext.GetLength() || match(fext, fileinfo.cFileName)))
  860. {
  861. m_pfiles->Add(path + fileinfo.cFileName);
  862. s = fileinfo.cFileName;
  863. file = s.Left( s.ReverseFind(_T('.')));
  864. m_pnames_noext->Add(file);
  865. }
  866. }
  867. }
  868. } while (FindNextFile(handle, &fileinfo));
  869. FindClose(handle);
  870. }
  871. }
  872. void findfile2::findfilesnames_within_subfolder_ex(IN CONST CString& folder, IN CONST CString& findext)
  873. {
  874. CString path = folder;
  875. if (path.GetLength() > 0 && _T('\\') != path[path.GetLength() - 1])
  876. path += _T("\\");
  877. CString fext = findext;
  878. if (fext == _T("*") || fext == _T("*.*"))
  879. fext = _T("");
  880. CString file = _T("*");
  881. CString s = path + file;
  882. WIN32_FIND_DATA fileinfo = { 0 };
  883. HANDLE handle = FindFirstFile(s, &fileinfo);
  884. if (NULL != handle && INVALID_HANDLE_VALUE != handle)
  885. {
  886. do
  887. {
  888. // 检查是否超过最大数;
  889. if (checklimit()) break;
  890. // '.'和 '..'的系统文件去除;
  891. if (_T('.') != fileinfo.cFileName[0])
  892. {
  893. if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY) // 目录;
  894. {
  895. m_pfolders->Add(fileinfo.cFileName);
  896. findfilesnames_within_subfolder_ex(path + fileinfo.cFileName, fext);
  897. }
  898. else
  899. {
  900. if (!checklimit() && (0 == fext.GetLength() || match(fext, fileinfo.cFileName)))
  901. {
  902. m_pfiles->Add(path + fileinfo.cFileName);
  903. s = fileinfo.cFileName;
  904. file = s.Left(s.ReverseFind(_T('.')));
  905. m_pnames_noext->Add(file);
  906. }
  907. }
  908. }
  909. } while (FindNextFile(handle, &fileinfo));
  910. FindClose(handle);
  911. }
  912. }
  913. //////////////////////////////////////////////////////////////////////////
  914. void findfile2::findfiles_bynames_findin_subfolder(IN CONST CString& folder, IN CONST CString& findext, IN /*CONST*/ CStringArray &exts, IN CStringArray &names)
  915. {
  916. CString path = folder;
  917. if (path.GetLength() > 0 && _T('\\') != path[path.GetLength() - 1])
  918. path += _T("\\");
  919. CString fext = findext;
  920. if (fext == _T("*") || fext == _T("*.*"))
  921. fext = _T("");
  922. CString file = _T("*");
  923. CString s = path + file;
  924. WIN32_FIND_DATA fileinfo = { 0 };
  925. HANDLE handle = FindFirstFile(s, &fileinfo);
  926. if (NULL != handle && INVALID_HANDLE_VALUE != handle)
  927. {
  928. do
  929. {
  930. // 检查是否超过最大数;
  931. if (checklimit()) break;
  932. // '.'和 '..'的系统文件去除;
  933. if (_T('.') != fileinfo.cFileName[0])
  934. {
  935. if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY) // 目录;
  936. {
  937. findfiles_bynames_findin_subfolder(path + fileinfo.cFileName, fext, exts, names);
  938. }
  939. else
  940. {
  941. if (!checklimit() && (0 == fext.GetLength() || match(fext, fileinfo.cFileName)))
  942. {
  943. bool bExist = false;
  944. CString str = getfilename(fileinfo.cFileName);
  945. for ( int i = names.GetSize() - 1; i > 0; i-- )
  946. {
  947. str.MakeLower();
  948. names.ElementAt(i).MakeLower();
  949. if ( str == names.ElementAt(i) )
  950. {
  951. bExist = true;
  952. names.RemoveAt(i);
  953. break;
  954. }
  955. }
  956. if (bExist)
  957. {
  958. if ( fext.IsEmpty() )
  959. {
  960. for ( int i = 0; i < m_vtEffctExt.GetSize(); i++ )
  961. {
  962. file = path + str + m_vtEffctExt.ElementAt(i);
  963. if ( PathFileExists(file) )
  964. {
  965. m_pfiles->Add(file);
  966. }
  967. }
  968. }
  969. else
  970. {
  971. for ( int i = 0; i < exts.GetSize(); i++ )
  972. {
  973. file = path + str + exts.ElementAt(i);
  974. if ( PathFileExists(file) )
  975. {
  976. m_pfiles->Add(file);
  977. }
  978. }
  979. }
  980. }
  981. }
  982. }
  983. }
  984. } while (FindNextFile(handle, &fileinfo));
  985. FindClose(handle);
  986. }
  987. }
  988. void findfile2::findfiles_bynames_findout_subfolder(IN CONST CString& folder, IN CONST CString& findext, IN /*CONST*/ CStringArray &exts, IN CStringArray &names)
  989. {
  990. CString path = folder;
  991. if (path.GetLength() > 0 && _T('\\') != path[path.GetLength() - 1])
  992. path += _T("\\");
  993. CString fext = findext;
  994. if (fext == _T("*") || fext == _T("*.*"))
  995. fext = _T("");
  996. CString file = _T("*");
  997. CString s = path + file;
  998. WIN32_FIND_DATA fileinfo = { 0 };
  999. HANDLE handle = FindFirstFile(s, &fileinfo);
  1000. if (NULL != handle && INVALID_HANDLE_VALUE != handle)
  1001. {
  1002. do
  1003. {
  1004. // 检查是否超过最大数;
  1005. if (checklimit()) break;
  1006. // '.'和 '..'的系统文件去除;
  1007. if (_T('.') != fileinfo.cFileName[0])
  1008. {
  1009. if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) != FILE_ATTRIBUTE_DIRECTORY) // 目录;
  1010. {
  1011. if (!checklimit() && (0 == fext.GetLength() || match(fext, fileinfo.cFileName)))
  1012. {
  1013. bool bExist = false;
  1014. CString str = getfilename(fileinfo.cFileName);
  1015. for ( int i = names.GetSize() - 1; i > 0; i-- )
  1016. {
  1017. str.MakeLower();
  1018. names.ElementAt(i).MakeLower();
  1019. if ( str == names.ElementAt(i) )
  1020. {
  1021. bExist = true;
  1022. names.RemoveAt(i);
  1023. break;
  1024. }
  1025. }
  1026. if (bExist)
  1027. {
  1028. if ( fext.IsEmpty() )
  1029. {
  1030. for ( int i = 0; i < m_vtEffctExt.GetSize(); i++ )
  1031. {
  1032. file = path + str + exts.ElementAt(i);
  1033. if ( PathFileExists(file) )
  1034. {
  1035. m_pfiles->Add(file);
  1036. }
  1037. }
  1038. }
  1039. else
  1040. {
  1041. for ( int i = 0; i < exts.GetSize(); i++ )
  1042. {
  1043. file = path + str + exts.ElementAt(i);
  1044. if ( PathFileExists(file) )
  1045. {
  1046. m_pfiles->Add(file);
  1047. }
  1048. }
  1049. }
  1050. }
  1051. }
  1052. }
  1053. }
  1054. } while (FindNextFile(handle, &fileinfo));
  1055. FindClose(handle);
  1056. }
  1057. }
  1058. void findfile2::findfiles_bynames_within_subfolder(IN CONST CString& folder, IN CONST CString& findext, IN /*CONST*/ CStringArray &exts, IN CStringArray &names)
  1059. {
  1060. CString path = folder;
  1061. if (path.GetLength() > 0 && _T('\\') != path[path.GetLength() - 1])
  1062. path += _T("\\");
  1063. CString fext = findext;
  1064. if (fext == _T("*") || fext == _T("*.*"))
  1065. fext = _T("");
  1066. CString file = _T("*");
  1067. CString s = path + file;
  1068. WIN32_FIND_DATA fileinfo = { 0 };
  1069. HANDLE handle = FindFirstFile(s, &fileinfo);
  1070. if (NULL != handle && INVALID_HANDLE_VALUE != handle)
  1071. {
  1072. do
  1073. {
  1074. // 检查是否超过最大数;
  1075. if (checklimit()) break;
  1076. // '.'和 '..'的系统文件去除;
  1077. if (_T('.') != fileinfo.cFileName[0])
  1078. {
  1079. if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY) // 目录;
  1080. {
  1081. m_pfolders->Add(fileinfo.cFileName);
  1082. findfiles_bynames_within_subfolder(path + fileinfo.cFileName, fext, exts, names);
  1083. }
  1084. else
  1085. {
  1086. if (!checklimit() && (0 == fext.GetLength() || match(fext, fileinfo.cFileName)))
  1087. {
  1088. bool bExist = false;
  1089. CString str = getfilename(fileinfo.cFileName);
  1090. for ( int i = names.GetSize() - 1; i > 0; i-- )
  1091. {
  1092. str.MakeLower();
  1093. names.ElementAt(i).MakeLower();
  1094. if ( str == names.ElementAt(i) )
  1095. {
  1096. bExist = true;
  1097. names.RemoveAt(i);
  1098. break;
  1099. }
  1100. }
  1101. if (bExist)
  1102. {
  1103. if ( fext.IsEmpty() )
  1104. {
  1105. for ( int i = 0; i < m_vtEffctExt.GetSize(); i++ )
  1106. {
  1107. file = path + str + exts.ElementAt(i);
  1108. if ( PathFileExists(file) )
  1109. {
  1110. m_pfiles->Add(file);
  1111. }
  1112. }
  1113. }
  1114. else
  1115. {
  1116. for ( int i = 0; i < exts.GetSize(); i++ )
  1117. {
  1118. file = path + str + exts.ElementAt(i);
  1119. if ( PathFileExists(file) )
  1120. {
  1121. m_pfiles->Add(file);
  1122. }
  1123. }
  1124. }
  1125. }
  1126. }
  1127. }
  1128. }
  1129. } while (FindNextFile(handle, &fileinfo));
  1130. FindClose(handle);
  1131. }
  1132. }
  1133. void findfile2::findfiles_withthumbnail_findin_subfolder(IN CONST CString& folder, IN CONST CString& findext)
  1134. {
  1135. CString path = folder;
  1136. if (path.GetLength() > 0 && _T('\\') != path[path.GetLength() - 1])
  1137. path += _T("\\");
  1138. CString fext = findext;
  1139. if (fext == _T("*") || fext == _T("*.*"))
  1140. fext = _T("");
  1141. CString file = _T("*");
  1142. CString s = path + file;
  1143. WIN32_FIND_DATA fileinfo = { 0 };
  1144. HANDLE handle = FindFirstFile(s, &fileinfo);
  1145. if (NULL != handle && INVALID_HANDLE_VALUE != handle)
  1146. {
  1147. do
  1148. {
  1149. // 检查是否超过最大数;
  1150. if (checklimit()) break;
  1151. // '.'和 '..'的系统文件去除;
  1152. if (_T('.') != fileinfo.cFileName[0])
  1153. {
  1154. if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY) // 目录;
  1155. {
  1156. findfiles_withthumbnail_findin_subfolder(path + fileinfo.cFileName, fext);
  1157. }
  1158. else
  1159. {
  1160. if (!checklimit() && (0 == fext.GetLength() || match(fext, fileinfo.cFileName)))
  1161. {
  1162. if ( fileinfo.cFileName[0] == _T('s') || fileinfo.cFileName[0] == _T('m') ||
  1163. fileinfo.cFileName[0] == _T('S') || fileinfo.cFileName[0] == _T('M'))
  1164. continue;
  1165. m_pfiles->Add(path + fileinfo.cFileName);
  1166. // 查找相应的s和m图,如果不存在,则使用""表示;
  1167. file = path + _T("s") + fileinfo.cFileName;
  1168. if ( PathFileExists(file) )
  1169. {
  1170. m_pvtfiles_sth->Add(file);
  1171. }
  1172. else
  1173. {
  1174. m_pvtfiles_sth->Add(_T(""));
  1175. }
  1176. file = path + _T("m") + fileinfo.cFileName;
  1177. if ( PathFileExists(file) )
  1178. {
  1179. m_pvtfiles_mth->Add(file);
  1180. }
  1181. else
  1182. {
  1183. m_pvtfiles_mth->Add(_T(""));
  1184. }
  1185. }
  1186. }
  1187. }
  1188. } while (FindNextFile(handle, &fileinfo));
  1189. FindClose(handle);
  1190. }
  1191. }
  1192. void findfile2::findfiles_withthumbnail_findout_subfolder(IN CONST CString& folder, IN CONST CString& findext)
  1193. {
  1194. CString path = folder;
  1195. if (path.GetLength() > 0 && _T('\\') != path[path.GetLength() - 1])
  1196. path += _T("\\");
  1197. CString fext = findext;
  1198. if (fext == _T("*") || fext == _T("*.*"))
  1199. fext = _T("");
  1200. CString file = _T("*");
  1201. CString s = path + file;
  1202. WIN32_FIND_DATA fileinfo = { 0 };
  1203. HANDLE handle = FindFirstFile(s, &fileinfo);
  1204. if (NULL != handle && INVALID_HANDLE_VALUE != handle)
  1205. {
  1206. do
  1207. {
  1208. // 检查是否超过最大数;
  1209. if (checklimit()) break;
  1210. // '.'和 '..'的系统文件去除;
  1211. if (_T('.') != fileinfo.cFileName[0])
  1212. {
  1213. if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) != FILE_ATTRIBUTE_DIRECTORY) // 目录;
  1214. {
  1215. if (!checklimit() && (0 == fext.GetLength() || match(fext, fileinfo.cFileName)))
  1216. {
  1217. if ( fileinfo.cFileName[0] == _T('s') || fileinfo.cFileName[0] == _T('m') ||
  1218. fileinfo.cFileName[0] == _T('S') || fileinfo.cFileName[0] == _T('M'))
  1219. continue;
  1220. m_pfiles->Add(path + fileinfo.cFileName);
  1221. // 查找相应的s和m图,如果不存在,则使用""表示;
  1222. file = path + _T("s") + fileinfo.cFileName;
  1223. if ( PathFileExists(file) )
  1224. {
  1225. m_pvtfiles_sth->Add(file);
  1226. }
  1227. else
  1228. {
  1229. m_pvtfiles_sth->Add(_T(""));
  1230. }
  1231. file = path + _T("m") + fileinfo.cFileName;
  1232. if ( PathFileExists(file) )
  1233. {
  1234. m_pvtfiles_mth->Add(file);
  1235. }
  1236. else
  1237. {
  1238. m_pvtfiles_mth->Add(_T(""));
  1239. }
  1240. }
  1241. }
  1242. }
  1243. } while (FindNextFile(handle, &fileinfo));
  1244. FindClose(handle);
  1245. }
  1246. }
  1247. void findfile2::findfiles_withthumbnail_within_subfolder(IN CONST CString& folder, IN CONST CString& findext)
  1248. {
  1249. CString path = folder;
  1250. if (path.GetLength() > 0 && _T('\\') != path[path.GetLength() - 1])
  1251. path += _T("\\");
  1252. CString fext = findext;
  1253. if (fext == _T("*") || fext == _T("*.*"))
  1254. fext = _T("");
  1255. CString file = _T("*");
  1256. CString s = path + file;
  1257. WIN32_FIND_DATA fileinfo = { 0 };
  1258. HANDLE handle = FindFirstFile(s, &fileinfo);
  1259. if (NULL != handle && INVALID_HANDLE_VALUE != handle)
  1260. {
  1261. do
  1262. {
  1263. // 检查是否超过最大数;
  1264. if (checklimit()) break;
  1265. // '.'和 '..'的系统文件去除;
  1266. if (_T('.') != fileinfo.cFileName[0])
  1267. {
  1268. if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY) // 目录;
  1269. {
  1270. findfiles_withthumbnail_within_subfolder(path + fileinfo.cFileName, fext);
  1271. }
  1272. else
  1273. {
  1274. if (!checklimit() && (0 == fext.GetLength() || match(fext, fileinfo.cFileName)))
  1275. {
  1276. if ( fileinfo.cFileName[0] == _T('s') || fileinfo.cFileName[0] == _T('m') ||
  1277. fileinfo.cFileName[0] == _T('S') || fileinfo.cFileName[0] == _T('M'))
  1278. continue;
  1279. m_pfiles->Add(path + fileinfo.cFileName);
  1280. // 查找相应的s和m图,如果不存在,则使用""表示;
  1281. file = path + _T("s") + fileinfo.cFileName;
  1282. if ( PathFileExists(file) )
  1283. {
  1284. m_pvtfiles_sth->Add(file);
  1285. }
  1286. else
  1287. {
  1288. m_pvtfiles_sth->Add(_T(""));
  1289. }
  1290. file = path + _T("m") + fileinfo.cFileName;
  1291. if ( PathFileExists(file) )
  1292. {
  1293. m_pvtfiles_mth->Add(file);
  1294. }
  1295. else
  1296. {
  1297. m_pvtfiles_mth->Add(_T(""));
  1298. }
  1299. }
  1300. }
  1301. }
  1302. } while (FindNextFile(handle, &fileinfo));
  1303. FindClose(handle);
  1304. }
  1305. }