Pages

Showing posts with label how to remove directory with C program. Show all posts
Showing posts with label how to remove directory with C program. Show all posts

Thursday, July 14, 2011

Remove Directory/Folder with C and C++ Program



The following program will show how to remove a directory/folder with C and C++. This program will store directory path and name from the user and then directory will be deleted with the rmdir() function. The rmdir() function will return 0 if directory is removed successfully otherwise it will return 1.



Directory removal program with C and C++

#include<stdio.h>

#include<conio.h>
#include<process.h>
#include<dir.h>

void main()


   int cheack;
   char *dirname;
   clrscr(); 
   printf("Enter a directory path and name to be deleted (C:/name):");
   gets(dirname);
   system("dir/p");
 
   cheack = rmdir(dirname);
   if (!cheack)
      printf("Directory deleted\n");
   else
   {   
            printf("Unable to remove directory\n");
            getch();
            exit(1);
   }
  getch();
}

Program Output

Enter a directory path and name to be deleted (C:/name):C:/test

Directory deleted.