1、__mkdir创建一次目录
char buf[80];
_getcwd(buf, sizeof(buf));//获取当前工程.cpp文件所在路径
strcat(buf, "\\pictureFile\\11");
string dirName = buf;
_mkdir(dirName.c_str());//一次创建两级目录
2、_mkdir多次创建目录
#include "stdafx.h"
#include<Windows.h>
#include <direct.h>
#include<iostream>
#include<time.h>
#include <io.h>
using namespace std;
//getcwd获取.cpp文件目录
int _tmain(int argc, _TCHAR* argv[])
{
time_t t;
struct tm * currentTime;
char CurrentTime[50];
char filePath[180];
char buf[80];
_getcwd(buf, sizeof(buf));//获取当前工程.cpp文件所在路径
strcat(buf, "\\series");
//string dirName = buf;
//_mkdir(dirName.c_str());//一次创建两级目录
int i = 5;
while (i--)
{
time(&t);//获取Unix时间戳。
currentTime = localtime(&t);//转为时间结构。
sprintf(CurrentTime, "%d%d%d%d%d%d", currentTime->tm_year + 1900, currentTime->tm_mon + 1, currentTime->tm_mday, currentTime->tm_hour + 8, currentTime->tm_min, currentTime->tm_sec);
if ((_access(buf, 0)) != -1)
{
sprintf(filePath, "%s\\%s", buf, CurrentTime);
string dirName = filePath;
_mkdir(dirName.c_str());
strcat(filePath, "\\ALLIED.bmp");
}
else{
string dirName = buf;
_mkdir(dirName.c_str());
sprintf(filePath, "%s\\%s", buf, CurrentTime);
string dirName2 = filePath;
_mkdir(dirName2.c_str());
strcat(filePath, "\\ALLIED.bmp");
}
Sleep(1000);
}
return 0;
}
运行结果:
创建了series文件夹,series文件夹里又创建了5个文件夹