用C++批量新建目录,示例代码如下:
#include <stdlib.h>
#include <unistd.h>
#include <string>
#include <sys/types.h>
#include <sys/stat.h>
#include <string>
#include <cstring>
#include <cstdlib>
using namespace std;
int main(){
char *img_dir = "/home/catkin_ws/img/";
string dirs[] = {"spring","summer","autumn","winter","hsv","hot","bone","ocean","cool","pink","jet","rainbow"};
char *style = nullptr;
for (auto c : dirs)
{
const char *type = c.c_str();
char *style = (char*)malloc(strlen(img_dir)+strlen(type)+1);
if (style == nullptr) exit (1);
strcpy(style, img_dir);
strcat(style, type);
fstream _file;
_file.open(style,ios::in);
if(!_file)
{
mkdir(style,S_IRWXU);
}
else
{
cout << "dir exists!!"<<endl;
}
}
}