Friday, January 3, 2014

how to delete a file using c program

how to delete a file using c program

This c program deletes a file which is entered by the user, the file to be deleted should be present in the directory in which the executable file of this program is present. Extension of the file should also be entered, also note that deleted file doesn't go to recycle bin, remove macro is used to delete the file. 

Code

#include<stdio.h>
#include<conio.h>
void main()
{
   int status;
   char file_name[25];
   printf("Enter the name of file you wish to delete\n");
   gets(file_name);
   status = remove(file_name);

   if( status == 0 )
      printf("%s file deleted successfully.\n",file_name);
   else
      printf("Unable to delete the file\n");
  
   getch();
   
}

No comments:

Post a Comment