Pages

Wednesday, April 9, 2014

Directory or Folder Creating Program with C C Language

Problem:  How to create a directory or folder

Solution

This is a program to make a folder or directory in a specific disk drive. To create a folder a function named 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<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
");


 else
 {
   
printf("Unable to create directory
");
   exit(1);
 }

 
getch();
  system("dir/p");
 
getch()
;
}


Output

Enter a directory path and name to be created (C:/name): C:/test.
Directory created.


Remark

Run this program and visit c drive. You will find a folder named TEST. If you don’t use path, you will find it in BIN directory.



Related Posts by Categories

0 comments:

Post a Comment