Create and Delete Directory in C++ programming by using mkdir() function to create a directory, and rmdir() function is used to remove any directory from the computer.
#include<iostream.h>
#include<conio.h>
#include<dir.h>
void main()
{ //creating Folder and assigning to 'status'.
cout<<"Creating directory"<<endl;
int status = mkdir("C://test/My New Folder");
if(status == 0) //if 'status' value Equal to 0 mean Created then.
{
cout<<"Directory Created";
}
else
{
cout<<"Directory not created";
}
getch();
}
#include<iostream.h>
#include<conio.h>
#include<dir.h>
void main()
{ //Deleting Folder and assigning to 'status'.
cout<<"Deleting directory..."<<endl;
int status = rmdir("C://test/My New Folder");
if(status == 0) //if 'status' value Equal to 0 mean Deleted then.
{
cout<<"Directory deleted!";
}
else
{
cout<<"Directory not deleted!";
}
getch();
}
#include<iostream.h>
#include<conio.h>
#include<dir.h> //including Library for working with Directory.
void main()
{
int done;
struct ffblk a;
cout<<"Press any key to view the files in the current directory"<<endl;
getch();
done = findfirst("*.*", &a, 0);
while(!done)
{
cout<<a.ff_name<<endl;
done = findnext(&a);
}
getch();
}