Create Directory or Folder with C/C++ Program

CC++Server Side ProgrammingProgramming

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
raja
Published on 16-Mar-2020 10:06:44
Advertisements