findfile.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /************************************************************************/
  2. /* Copyright (C), 2016-2020, [IT], 保留所有权利;
  3. /* 模 块 名:;
  4. /* 描 述:;
  5. /*
  6. /* 版 本:[V];
  7. /* 作 者:[IT];
  8. /* 日 期:[12/22/2016];
  9. /*
  10. /*
  11. /* 注 意:;
  12. /*
  13. /* 修改记录:[IT];
  14. /* 修改日期:;
  15. /* 修改版本:;
  16. /* 修改内容:;
  17. /************************************************************************/
  18. #ifndef __FIND_FILE_20151003__
  19. #define __FIND_FILE_20151003__
  20. #include <string>
  21. #include <vector>
  22. using namespace std;
  23. #ifndef _UNICODE
  24. typedef string TString;
  25. #else
  26. typedef wstring TString;
  27. #endif
  28. typedef vector<TString> STR_VEC;
  29. #pragma once
  30. class findfile
  31. {
  32. public:
  33. findfile(void);
  34. virtual ~findfile(void);
  35. //protected:
  36. public:
  37. INT m_nlimit;
  38. STR_VEC m_vtEffctExt;
  39. STR_VEC *m_pvtfiles;
  40. STR_VEC *m_pvtnames;
  41. STR_VEC *m_pvtfolders;
  42. STR_VEC *m_pvtfiles_sth; // s小图;
  43. STR_VEC *m_pvtfiles_mth; // m小图;
  44. public:
  45. static inline int findfile::match(IN CONST TString &strExt, IN CONST TString &strfile)
  46. {
  47. int pos = strfile.find_last_of(_T('.'));
  48. if (TString::npos != pos)
  49. return !_tcsicmp(strExt.c_str(), strfile.substr(pos).c_str());
  50. return FALSE;
  51. }
  52. static TString getfilename(IN CONST TString &file);
  53. protected:
  54. INT getlimit() const { return m_nlimit; }
  55. void setlimit(IN CONST INT &nlimit);
  56. inline INT checklimit() { return m_pvtfiles->size() == getlimit(); }
  57. BOOL IsaDirectory(CONST TString &sDirectory) { return (FILE_ATTRIBUTE_DIRECTORY == GetFileAttributes(sDirectory.c_str())); }
  58. public:
  59. void find1st(TString folder, TString &file);
  60. // 查找所有文件,包括子文件夹名、文件名、文件路径;
  61. void findall(IN CONST TString& folder);
  62. // 只返回2级子目录名(测试ok);
  63. void findsubfolder(IN CONST TString& folder);
  64. // 只返回所有子目录名(测试ok);
  65. void findallsubfolder(IN CONST TString& folder);
  66. // 查找文件路径,以及查找子目录的文件路径,但不获取子目录名(测试ok);
  67. void findfiles_findin_subfolder(IN CONST TString& folder);
  68. // 查找文件路径,不查找子目录的文件(测试ok);
  69. void findfiles_findout_subfolder(IN CONST TString& folder);
  70. // 查找文件路径,以及查找子目录的文件路径,同时获取子目录名(测试ok);
  71. void findfiles_within_subfolder(IN CONST TString& folder);
  72. };
  73. #endif