1. 获取系统时间
参考:
https://blog.csdn.net/weixin_44032878/article/details/88035449
2. 创建文件夹
参考:
https://www.jianshu.com/p/06a0da1f6389
http://www.360doc.com/content/16/0929/10/478627_594579903.shtml
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
#include <iostream>
int main()
{
//获取当前系统时间
time_t timep;
char path[256] = {0};
time(&timep);//获取从1970至今过了多少秒,存入time_t类型的timep
strftime(path, sizeof(path), "%Y-%m-%d-%H-%M-%S",localtime(&timep) ); //最后一个参数是用localtime将秒数转化为struct tm结构体
printf("path = %s\n", path);
//检查文件夹是否存在
if(access(path, 0) == -1)//access函数查看文件夹是否存在
{
//如果不存在,就用mkdir函数来创建
int isCreate = mkdir(path,S_IRUSR | S_IWUSR | S_IXUSR | S_IRWXG | S_IRWXO);
if( !isCreate )
std::cout<<"create path: "<<path<<std::endl;
else
std::cout<<"create path failed!"<<std::endl;
}else
{
std::cout<<"existed!"<<std::endl;
}
return 0;
}