Create and Delete Directory in C

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.

Program Creating Directory

Program

#include<stdio.h>
#include<conio.h>
#include<dir.h>
void main()
{            //creating Folder and assigning to 'status'.
printf("Creating directory\n");
int status = mkdir("C://test/My New Folder");
if(status == 0) //if 'status' value Equal to 0 mean Created then.
{
printf("Directory Created");
}
else
{
printf("Directory not created");
}
getch();
}
Output
Creating directory
Directory Created

Program Deleting Directory

Program

#include<stdio.h>
#include<conio.h>
#include<dir.h>
void main()
{            //Deleting Folder and assigning to 'status'.
printf("Deleting directory...\n");
int status = rmdir("C://test/My New Folder");
if(status == 0) //if 'status' value Equal to 0 mean Deleted then.
{
printf("Directory deleted!");
}
else
{
printf("Directory not deleted!");
}
getch();
}
Output
Deleting directory...
Directory deleted!

Program Showing All Files in Directory

Program

#include<stdio.h>
#include<conio.h>
#include<dir.h> //including Library for working with Directory.
void main()
{
int done;
struct ffblk a;
printf("Press any key to view the files in the current directory\n");
getch();
done = findfirst("*.*", &a, 0);
while(!done)
{
printf("%s\n", a.ff_name);
done = findnext(&a);
}
getch();
}
Output
Press any key to view the files in the current directory
32rtm.exe
addonreg.exe
autogen.exe
b32tools.pif
bc520rtl.dll
bcc.exe
BCC32.CFG
bcc32.exe
BCCONFIG.BCW
BCROOT.INC
bcw.exe
bcwaddon.dll
bcwdbg.dll
bcwdbgv.dll
.
.
.