__mkdir创建目录

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个文件夹

  • 4
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值