mkdir function :
mkdir function creates a DOS directory by given path. if directory is successfully created then function will return 0 and if any error occures it will return -1.
General syntax of the "mkdir" function is a follows :
int mkdir(const char *path);
Example of mkdir function :
#include<iostream.h>
#include<conio.h>
#include<dir.h>
void main()
{
clrscr();
char name[12];
cout <<"enter directory name to be created";
cin >> name;
int c=mkdir(name);
if (c==0)
{
cout <<"directory created";
}
else
{
cout << "directory cannot be created";
}
getch();
}
Above program will asks user to enter a directory name to be created. when user enters a directory name and presses enter directory will be created. A message appears too that directory will be created successfully or not.
rmdir function :
rmdir function removes a DOS directory by given path. if directory is successfully deleted from the DOS it will return 0 and suppose if any error occures it will return -1.
General syntax of the "rmdir" function is as follows :
int rmdir(const char *path);
although rmdir deletes the directory by given path but following conditions must be met before deleting any directory by rmdir function
1. directory must be empty
2. directory must not be current working directory
Example of rmdir function :
#include<iostream.h>
#include<conio.h>
#include<dir.h>
void main()
{
clrscr();
char name[12];
cout <<"enter directory name to be created";
cin >> name;
int c=rmdir(name);
if (c==0)
{
cout <<"directory deleted";
}
else
{
cout << "directory cannot be deleted";
}
getch();
}
Above program will asks user to enter a directory name to be deleted. when user enters a directory name and presses enter directory will be deleted. A message will be appeared that directory successfully created or not.
Technorati Tags: dir.h, C++, Programs
No comments:
Post a Comment