第一种:
调用MFC封装好的接口函数,主要会用到
PathIsDirectory //判断是否存在
::CreateDirectory //创建
例如:
#include "shlwapi.h"
#pragma comment(lib,"shlwapi.lib")
#include <afx.h>
CString path = "../../../STL/stl2";
if (!PathIsDirectory(path))
{
::CreateDirectory(path, 0);
}
编写C/C++函数实现该功能
例如:
#include <io.h>
#include <direct.h>
#define PATH_DELIMITER '\\'
bool createDirectory(const std::string folder) {
std::string folder_builder;
std::string sub;
sub.reserve(folder.size());
for (auto it = folder.begin(); it != folder.end(); ++it)
{
//cout << *(folder.end()-1) << endl;
const char c = *it;
sub.push_back(c);
if (c == PATH_DELIMITER || it == folder.end() - 1)
{
folder_builder.append(sub);
if (0 != ::_access(folder_builder.c_str(), 0))
{
// this folder not exist
if (0 != ::_mkdir(folder_builder.c_str()))
{
// create failed
return false;
}
}
sub.clear();
}
}
return true;
}
const std::string path2 = "..\\..\\..\\STL\\stl2";
createDirectory(path2);
第三种:
调用DOS命令
例如:
#include <stdlib.h>
system("md stl2");
参考:https://github.com/liuruoze/EasyPR.git