Implffsco.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #ifndef __FIND_FILES_COLLECTION__
  2. #define __FIND_FILES_COLLECTION__
  3. #ifndef WIN32
  4. #error now only for WIN32(platform).
  5. #endif
  6. #include <string>
  7. #include <vector>
  8. using namespace std;
  9. #ifdef UNICODE
  10. typedef wstring TString;
  11. #else
  12. typedef string TString;
  13. #endif
  14. #pragma once
  15. // advanced find files collection;
  16. namespace affsco
  17. {
  18. CONST INT nMaxLimit = 0x100000; //--1048576
  19. CONST INT nDefLimit = 0x10000; //--65536
  20. CONST TCHAR c_pathSeparator = _T('\\');
  21. CONST TString s_pathSeparator = _T("\\");
  22. class Implffsco
  23. {
  24. INT m_nLimit;
  25. INT m_nIsonym; // ÎļþÃûÏàͬµÄ´ÎÊý;
  26. BOOL m_bFindSubFolders;
  27. vector<TString> m_vtAllFiles;
  28. vector<TString> m_vtSubFolders;
  29. vector<TString> m_vtFiles;
  30. vector<TString> m_vtJustFNames;
  31. private:
  32. inline INT CheckLimit() {
  33. return GetAllFilesCount() == GetLimit();
  34. }
  35. inline static TString UpperCase(IN const TString &Str){
  36. const TCHAR aazz = _T('z') - _T('Z');
  37. TString sResult;
  38. for (TString::const_iterator it = Str.begin(); Str.end() != it; it++)
  39. {
  40. if (_T('a') <= *it && *it <= _T('z'))
  41. sResult.append(1, *it - aazz);
  42. else
  43. sResult.append(1, *it);
  44. }
  45. return sResult;
  46. }
  47. public:
  48. Implffsco(void);
  49. ~Implffsco(void);
  50. static int Match(IN CONST TString &sExt, IN CONST TString &sFile);
  51. TString GetFileName(CONST INT &nPos = 0){
  52. return m_vtAllFiles.at(nPos);
  53. }
  54. INT GetAllFilesCount() {
  55. return m_vtFiles.size() + m_vtSubFolders.size();
  56. }
  57. INT GetFilesCount() {
  58. return m_vtFiles.size();
  59. }
  60. INT GetDirsCount(){
  61. return m_vtSubFolders.size();
  62. }
  63. CONST vector<TString> &GetAllFiles()CONST {
  64. return m_vtAllFiles;
  65. }
  66. CONST vector<TString> &GetFiles()CONST {
  67. return m_vtFiles;
  68. }
  69. CONST vector<TString> &GetSubFolders()CONST {
  70. return m_vtSubFolders;
  71. }
  72. CONST vector<TString> &GetFNames()CONST {
  73. return m_vtJustFNames;
  74. }
  75. INT GetLimit() const {
  76. return m_nLimit;
  77. }
  78. inline void SetLimit(IN CONST INT &nLimit) {
  79. if(nLimit < 1)
  80. m_nLimit = nDefLimit;
  81. if (nLimit < nMaxLimit )
  82. m_nLimit = nLimit;
  83. }
  84. BOOL IsFindSubFolders() const {
  85. return m_bFindSubFolders;
  86. }
  87. void SetFindDir(BOOL bFindSubFolders=TRUE) {
  88. m_bFindSubFolders = bFindSubFolders;
  89. }
  90. BOOL IsaDirectory(CONST TString &sDirectory){
  91. return (FILE_ATTRIBUTE_DIRECTORY == GetFileAttributes(sDirectory.c_str()));
  92. }
  93. VOID ReCleart(){
  94. m_vtAllFiles.clear();
  95. m_vtFiles.clear();
  96. m_vtSubFolders.clear();
  97. m_vtJustFNames.clear();
  98. }
  99. VOID FindFiles(IN CONST TString& sTargetDirectory, IN CONST TString& sFileExt);
  100. VOID FindFilesEx(IN CONST TString& sTargetDirectory, IN CONST TString& sFileExt);
  101. VOID JustFindNames(IN CONST TString& sTargetDirectory, IN CONST TString& sFileExt);
  102. };
  103. };
  104. #endif