#include <iostream>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
using namespace std;
int main()
{
char pFileName[]= "./aaa/bbb/ccc/ddd.jpg";
char *pBeg = pFileName + 1, *pPos = NULL;
while ((pPos = strchr(pBeg, '/')) != NULL)
{
*pPos = '\0';
if (access(pFileName, F_OK) != 0)
mkdir(pFileName, 0777);
//cout << pFileName << endl;
*pPos = '/';
pBeg = pPos + 1;
if (*pBeg == '\0')
break;
}
return 0;
}
结果: