Directory or Folder Creating Program with C/C++ Language
Problem: How to create a directory or folder
Solution
#include<stdio.h>
#include<conio.h>
#include<process.h>
#include<dir.h>
void main()
{
int check;
char *dirname;
clrscr();
printf("Enter a directory path and name to be created (C:/name):");
gets(dirname);
check = mkdir(dirname);
if (!check)
printf("Directory created\n");
else
{
printf("Unable to create directory\n");
exit(1);
}
getch();
system("dir/p");
getch();
}
Solution
This is a program to make a folder or directory in a specific disk drive. To create a folder a functionnamed mkdir () is used here. Within the parenthesis, you have to put the specific disk drive and folder name like C:/name. Programming code for creating a directory goes below.
Example: Code to create a folder or directory
#include<conio.h>
#include<process.h>
#include<dir.h>
void main()
{
int check;
char *dirname;
clrscr();
printf("Enter a directory path and name to be created (C:/name):");
gets(dirname);
check = mkdir(dirname);
if (!check)
printf("Directory created\n");
else
{
printf("Unable to create directory\n");
exit(1);
}
getch();
system("dir/p");
getch();
}
No comments:
Post a Comment