windows下创建多级目录(C++)

下面是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;
}
发布了44 篇原创文章 · 获赞 7 · 访问量 6844

猜你喜欢

转载自blog.csdn.net/hongge_smile/article/details/104366056