Home >Backend Development >C++ >Create a directory or folder using a C/C++ program

Create a directory or folder using a C/C++ program

PHPz
PHPzforward
2023-08-28 23:17:061703browse

Create a directory or folder using a C/C++ program

In this tutorial, we will discuss a program to create a directory or folder using a C/C program.

To create a new directory, we will use the mkdir() command. Please note that the given code only works with the 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

The above is the detailed content of Create a directory or folder using a C/C++ program. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete