#include <#include <stdio.h>
#include <#include <stdlib.h>
#include <#include <sys/stat.h>
char* strCat = (char*)malloc(200);
void main()
{
char folderName[] = "./image_dst"; //当前目录下的image_dst文件夹;
struct stat buffer;
int a = (stat(folderName, &buffer) == 0); //判断文件夹是否存在,不存在创建;
if (a==0)
{
_mkdir(folderName); //不存在则创建;
}
sprintf(strCat, "%s\\%s", folderName,gain); //当前目录下的gain(gain为变量)文件夹;
int b = (stat(strCat, &buffer) == 0); //判断文件夹是否存在,不存在创建;
if (b == 0)
{
_mkdir(strCat); //不存在则创建;
}
sprintf(strCat, "%s\\%s&%s", strCat, name_p, name_c);
int c = (stat(strCat, &buffer) == 0); //判断文件夹是否存在,不存在创建;
if (c == 0)
{
_mkdir(strCat); //不存在则创建;
}
free(strCat );
return;
}
本文介绍如何使用C++通过`stat`和`mkdir`函数判断并创建文件夹,包括递归创建子目录的情况。重点在于文件夹路径的构建和错误处理。
710

被折叠的 条评论
为什么被折叠?



