Make dir in C, linux doesnt create sub-dirs (dir tree) - why? -


i want create dir tree in c on linux. wrote code:

#include <sys/types.h> #include <sys/stat.h> #include <stdio.h> #include <stdlib.h>  static int direxists(const char *path) {     struct stat info;      if(stat( path, &info ) != 0)         return 0;     else if(info.st_mode & s_ifdir)         return 1;     else         return 0; }  int main(int argc, char **argv) {     const char *path = "./mydir/firstdir/";      if(!direxists(path))     {         mode_t mask = umask(0);         if(mkdir(path, s_irwxu | s_irwxg | s_irwxo) == -1)             exit(-1);         umask(mask);     }      printf("%d\n", direxists(path));     return 0; } 

its ok when path single dir, lets say, path = "./mydir" when want create dir tree, example: path = "./mydir/a/b/c/d/" dirs not created. why?

you need define code able create directory tree. in other word mkdir doesn't create directory recursively.

edit: in link you've posted parent directory exists.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -