Create Directory or Folder with C/C++ Program


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

Updated on: 16-Mar-2020

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements