stdafx.cpp 918 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // stdafx.cpp : 只包括标准包含文件的源文件
  2. // TestWizard.pch 将作为预编译头
  3. // stdafx.obj 将包含预编译类型信息
  4. #include "stdafx.h"
  5. // TODO: 在 STDAFX.H 中
  6. // 引用任何所需的附加头文件,而不是在此文件中引用
  7. bool MKDIR(LPCTSTR dir)
  8. {
  9. int nleft = 0;
  10. int nIndex = -1;
  11. std::string strdir = dir;
  12. strdir = strdir.substr(0, strdir.find_last_of(_T("\\")));
  13. if (strdir.at(strdir.size() - 1) != _T('\\'))
  14. strdir.append(_T("\\"));
  15. // 共享路径和硬盘盘符;
  16. if (_tcscmp(strdir.substr(0, 2).c_str(), _T("\\\\")) == 0)
  17. nleft = strdir.find_first_of(_T("\\"), 2) + 1; // 去除共享主机名;
  18. else if (strdir.at(2) == _T('\\'))
  19. nleft = 3;
  20. do {
  21. nIndex = strdir.substr(nleft, -1).find_first_of(_T("\\"));
  22. if (nIndex != std::string::npos) {
  23. if (_mkdir(strdir.substr(0, nIndex + nleft).c_str()) == -1 && (errno != EEXIST)) {
  24. return false;
  25. }
  26. nleft += nIndex + 1;
  27. }
  28. } while (nIndex != -1);
  29. return true;
  30. };