C++文件夹操作之自动创建
1.读取系统时间自动创建
#include<io.h>
#include<direct.h>
#include<time.h>
std::string imgspath = ".\\test2\\jpgs";
std::string savepath = ".\\test2\\result\\";
struct tm t;
time_t now;
time(&now);
localtime_s(&t, &now);
char cNowTime[64];
strftime(cNowTime, sizeof(cNowTime), "%Y%m%d-%H%M%S", &t);
std::string timedir;
timedir = cNowTime;
std::string dir = (savepath + timedir).c_str();
if (_access(dir.c_str(), 0) == -1)
{
_mkdir(dir.c_str());
}
std::string dir_yes = dir + ".\\success";
std::string dir_0 = dir + ".\\Error0";
std::string dir_1 = dir + ".\\Error1";
std::string dir_2 = dir + ".\\Error2";
_mkdir(dir_yes.c_str());
_mkdir(dir_0.c_str());
_mkdir(dir_1.c_str());
_mkdir(dir_2.c_str());
![在这里插入图片描述](https://img-blog.csdnimg.cn/d8785e1489bd4f9497c62a3fcd5fad63.png)