#include <sys/types.h>
      #include <sys/stat.h>
      #include <unistd.h>
      #include <string>
      int createDir(){
        struct stat st = {0};
        //checking if the directory exists
        if (stat("newdir", &st) == -1) {
          mkdir("newdir", 0755);
        std::string mydir = "mydir";
        //need to convert from std::string to const char*
        if (stat(mydir.c_str(), &st) == -1) { //checking if the directory exists
          mkdir(mydir.c_str(), 0755);

      Cpp language logo
      Create directory

      Codiga's C++ Recipes

      Create a directory if it doesn't exist


        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.