Search code examples
cmkdir

how to create folders using mkdir in c?


I'm trying to create a folder using mkdir in C but it wont't work

the code won't create the folders

#include <sys/stat.h>
#include <sys/types.h>
#include <stdio.h>
#include <string.h>

int main (){
    char chemin[256];
    char name[20];
    //char fichier[100];                                                        
//  FILE *fp;                                                                   
    strcpy(chemin,"/home/Deva/Documents/prog/C/la/sds");

    mkdir(chemin,0755);
    if (mkdir(chemin,0755)==-1){
        printf("\nERROR\n");
    } else { printf("fichier creer"); }
}

Solution

  • you are passing PATH not just directory name. so please check below post would help

    Recursive mkdir() system call on Unix