Implffsco.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. #include "StdAfx.h"
  2. #include "Implffsco.h"
  3. //extern void IsonymLog(LPCTSTR lpLog,BOOL bLogModel);
  4. namespace affsco
  5. {
  6. Implffsco::Implffsco(void)
  7. {
  8. m_nLimit = nDefLimit;
  9. m_nIsonym = 0;
  10. m_bFindSubFolders = FALSE;
  11. }
  12. Implffsco::~Implffsco(void)
  13. {
  14. m_vtAllFiles.clear();
  15. m_vtFiles.clear();
  16. m_vtJustFNames.clear();
  17. m_vtSubFolders.clear();
  18. }
  19. int Implffsco::Match(IN CONST TString &sFileExt, IN CONST TString &sFile)
  20. {
  21. TString fext = UpperCase(sFileExt);
  22. TString file = UpperCase(sFile);
  23. int pos = file.find_last_of(_T('.'));
  24. if (TString::npos != pos)
  25. file = file.substr(pos);
  26. return (TString::npos != fext.find(file));
  27. }
  28. VOID Implffsco::FindFiles(IN CONST TString& sTargetDirectory, IN CONST TString& sFileExt)
  29. {
  30. TString path = sTargetDirectory;
  31. if (path.size() > 0 && c_pathSeparator != path[path.size() - 1])
  32. path.append(s_pathSeparator);
  33. TString fext = sFileExt;
  34. if (0 == fext.compare(_T("*")) || 0 == fext.compare(_T("*.*")))
  35. fext = _T("");
  36. TString file = _T("*");
  37. TString s = path + file;
  38. WIN32_FIND_DATA fileinfo = { 0 };
  39. HANDLE handle = FindFirstFile(s.c_str(), &fileinfo);
  40. if (NULL != handle && INVALID_HANDLE_VALUE != handle)
  41. {
  42. do
  43. {
  44. // 检查是否超过最大数;
  45. if (CheckLimit()) break;
  46. // '.'和 '..'的系统文件去除;
  47. if (_T('.') != fileinfo.cFileName[0])
  48. {
  49. if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY) // 目录;
  50. {
  51. if (m_bFindSubFolders)
  52. {
  53. m_vtSubFolders.push_back(path + fileinfo.cFileName);
  54. FindFiles(path+fileinfo.cFileName,fext);
  55. }
  56. }
  57. else
  58. {
  59. //--limit test
  60. if (!CheckLimit() && (0 == fext.size() || Match(fext, fileinfo.cFileName)))
  61. {
  62. m_vtFiles.push_back(path + fileinfo.cFileName);
  63. }
  64. }
  65. }
  66. } while (FindNextFile(handle, &fileinfo));
  67. FindClose(handle);
  68. }
  69. }
  70. VOID Implffsco::FindFilesEx(IN CONST TString& sTargetDirectory, IN CONST TString& sFileExt)
  71. {
  72. TString path = sTargetDirectory;
  73. if (path.size() > 0 && c_pathSeparator != path[path.size() - 1])
  74. path.append(s_pathSeparator);
  75. TString fext = sFileExt;
  76. if (0 == fext.compare(_T("*")) || 0 == fext.compare(_T("*.*")))
  77. fext = _T("");
  78. TString file = _T("*");
  79. TString s = path + file;
  80. WIN32_FIND_DATA fileinfo = { 0 };
  81. HANDLE handle = FindFirstFile(s.c_str(), &fileinfo);
  82. if (NULL != handle && INVALID_HANDLE_VALUE != handle)
  83. {
  84. do
  85. {
  86. // 检查是否超过最大数;
  87. if (CheckLimit()) break;
  88. // '.'和 '..'的系统文件去除;
  89. if (_T('.') != fileinfo.cFileName[0])
  90. {
  91. if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY) // 目录;
  92. {
  93. if (m_bFindSubFolders)
  94. {
  95. m_vtSubFolders.push_back(path + fileinfo.cFileName);
  96. FindFilesEx(path+fileinfo.cFileName,fext);
  97. }
  98. }
  99. else
  100. {
  101. //--limit test
  102. if (!CheckLimit() && (0 == fext.size() || Match(fext, fileinfo.cFileName)))
  103. {
  104. m_vtFiles.push_back(path + fileinfo.cFileName);
  105. m_vtJustFNames.push_back(fileinfo.cFileName);
  106. }
  107. }
  108. }
  109. } while (FindNextFile(handle, &fileinfo));
  110. FindClose(handle);
  111. }
  112. }
  113. VOID Implffsco::JustFindNames(IN CONST TString& sTargetDirectory, IN CONST TString& sFileExt)
  114. {
  115. TString path = sTargetDirectory;
  116. if (path.size() > 0 && c_pathSeparator != path[path.size() - 1])
  117. path.append(s_pathSeparator);
  118. TString fext = sFileExt;
  119. if (0 == fext.compare(_T("*")) || 0 == fext.compare(_T("*.*")))
  120. fext = _T("");
  121. TString file = _T("*");
  122. TString s = path + file;
  123. WIN32_FIND_DATA fileinfo = { 0 };
  124. HANDLE handle = FindFirstFile(s.c_str(), &fileinfo);
  125. if (NULL != handle && INVALID_HANDLE_VALUE != handle)
  126. {
  127. do
  128. {
  129. // 检查是否超过最大数;
  130. if (CheckLimit()) break;
  131. // '.'和 '..'的系统文件去除;
  132. if (_T('.') != fileinfo.cFileName[0])
  133. {
  134. if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY) // 目录;
  135. {
  136. JustFindNames(path+fileinfo.cFileName,fext);
  137. }
  138. else
  139. {
  140. //--limit test
  141. if (!CheckLimit() && (0 == fext.size() || Match(fext, fileinfo.cFileName)))
  142. {
  143. m_vtJustFNames.push_back(fileinfo.cFileName);
  144. }
  145. }
  146. }
  147. } while (FindNextFile(handle, &fileinfo));
  148. FindClose(handle);
  149. }
  150. }
  151. };