filehelper.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #include "pch.h"
  2. #include "filehelper.h"
  3. #include <shlwapi.h>
  4. // 排序和乱序使用stl;
  5. #include <cstdlib>
  6. #include <ctime>
  7. #include <algorithm>
  8. // _mkdir头文件;
  9. #include <direct.h>
  10. int myrandom(int i) { return std::rand() % i; }
  11. filehelper::filehelper(void)
  12. {
  13. }
  14. filehelper::~filehelper(void)
  15. {
  16. }
  17. /************************************************************************/
  18. /* 函数:[2/21/2017 Jeff];
  19. /* 描述:;
  20. /* 参数:;
  21. /* [IN] :;
  22. /* [OUT] :;
  23. /* [IN/OUT] :;
  24. /* 返回:void;
  25. /* 注意:;
  26. /* 示例:;
  27. /*
  28. /* 修改:;
  29. /* 日期:;
  30. /* 内容:;
  31. /************************************************************************/
  32. void filehelper::random(IN STR_VEC& vtContent, IN BOOL bSort /* = TRUE */)
  33. {
  34. if (bSort)
  35. {//排序;
  36. std::sort(vtContent.begin(), vtContent.end());
  37. }
  38. else
  39. {//乱序;
  40. //设置随即数生成器的种子;
  41. std::srand(unsigned(std::time(0)));
  42. std::random_shuffle(vtContent.begin(), vtContent.end(), myrandom);
  43. }
  44. }
  45. /************************************************************************/
  46. /* 函数:[2/21/2017 Jeff];
  47. /* 描述:;
  48. /* 参数:;
  49. /* [IN] :;
  50. /* [OUT] :;
  51. /* [IN/OUT] :;
  52. /* 返回:void;
  53. /* 注意:;
  54. /* 示例:;
  55. /*
  56. /* 修改:;
  57. /* 日期:;
  58. /* 内容:;
  59. /************************************************************************/
  60. void filehelper::split(OUT vector<TString>& vtSplit, IN const TString str, IN const TString strSplit)
  61. {
  62. if (str.size() == 0 || strSplit.size() == 0)
  63. return;
  64. INT nIndex = 0;
  65. vtSplit.clear();
  66. TString strtmp = str;
  67. TString strtmp2;
  68. do
  69. {
  70. if (TString::npos != (nIndex = strtmp.find_first_of(strSplit)))
  71. {
  72. strtmp2 = strtmp.substr(0, nIndex);
  73. if (strtmp2.size())vtSplit.push_back(strtmp2);
  74. strtmp = strtmp.substr(nIndex + strSplit.size());
  75. }
  76. } while (strtmp.find_first_of(strSplit) != TString::npos);
  77. if (strtmp.size())
  78. vtSplit.push_back(strtmp);
  79. }
  80. //////////////////////////////////////////////////////////////////////////
  81. BOOL filehelper::getsubfolder(LPCTSTR lpfolder, STR_VEC *pvtfolders)
  82. {
  83. // 路径不存在;
  84. if (!PathFileExists(lpfolder))
  85. return FALSE;
  86. // 指针空;
  87. if (pvtfolders == NULL) return FALSE;
  88. m_pvtfolders = pvtfolders;
  89. findsubfolder(lpfolder);
  90. return TRUE;
  91. }
  92. //////////////////////////////////////////////////////////////////////////
  93. BOOL filehelper::getallfiles(LPCTSTR lpfolder, LPCTSTR lpfindext, STR_VEC *pvtfiles)
  94. {
  95. // 路径不存在;
  96. if (!PathFileExists(lpfolder))
  97. return FALSE;
  98. // 指针空;
  99. if (pvtfiles == NULL) return FALSE;
  100. m_pvtfiles = pvtfiles;
  101. findfiles_findin_subfolder(lpfolder);
  102. return TRUE;
  103. }
  104. BOOL filehelper::getfolderfiles(LPCTSTR lpfolder, LPCTSTR lpfindext, STR_VEC *pvtfiles)
  105. {
  106. // 路径不存在;
  107. if (!PathFileExists(lpfolder))
  108. return FALSE;
  109. // 指针空;
  110. if (pvtfiles == NULL) return FALSE;
  111. m_pvtfiles = pvtfiles;
  112. findfiles_findout_subfolder(lpfolder);
  113. return TRUE;
  114. }