In this tutorial, we will be discussing a program to create directory or folder with C/C++ program.
To create a new directory we will be using the mkdir() command. Note that the given code will work only for windows compiler.
Example
#include <conio.h> #include <dir.h> #include <process.h> #include <stdio.h> void main(){ int check; char* dirname = "tutorialspoint"; clrscr(); check = mkdir(dirname); //checking if directory is created if (!check) printf("Directory created\n"); else { printf("Unable to create directory\n"); exit(1); } getch(); system("dir/p"); getch(); }
Output
Directory created