下面是C++在windows下创建多级目录的代码:
#include <iostream>
#include <string>
#include <imagehlp.h>
using namespace std;
bool createDirs(std::string &path)
{
char last_char;
last_char = path.back();
if (last_char != '\\')
{
path += '\\';
}
PCSTR pcPath = path.c_str();
bool result = MakeSureDirectoryPathExists(pcPath);
return result;
}
int main()
{
//string path = ".\\img\\z投影\\2020-02-17\\7777\\";
//string path = "..\\img\\z投影\\2020-02-17\\7777\\";
//string path = "img\\z投影\\2020-02-17\\7777\\";
//string path = "C:\\Users\\lenovo\\Desktop\\dirtest";
string path = "C:\\Users\\lenovo\\Desktop\\dirtest\\";
getTime(time);
getDate(date);
bool result=0;
result = createDirs(path);
std::cout << "result: "<< result << std::endl;
}