Home C-tutorials C file delete example
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

C file delete example

Advertisement
This section illustrates you to delete a file in C. You can see in the given example that we want to remove the file HELLO.txt.

C file delete example

     

This section illustrates you to delete a file in C. You can see in the given example that we want to remove the file HELLO.txt. For this, we have used the library function remove() which deletes the file HELLO.txt. In case if the file will not be deleted, the function perror() prints the error message on the console.

Here i am using TurboC++ IDE and my source file is in the C:\TC\BIN directory and the file to be deleted Hello.txt  should be first placed inside the same bin directory.

Here is the code:

FILEDELE.C

#include <stdio.h>
#include <conio.h>
void main() {
  if (remove("HELLO.txt"== -1)
  perror("Error in deleting a file");
  getch();
}

When you run the above example, the file HELLO.txt gets removed.

Download Source Code:

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: February 5, 2009

Related Tutorials

Ask Questions?    Discuss: C file delete example  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
Chengetai Kadenge
October 30, 2011
Thank you

Saw the code to delete a file. Thank you so much. It helped a lot.
chiranjit ghosh
January 3, 2012
computer science

thanks a lot.....
Nitesh
January 15, 2012
Thankyou

Thanks for the example
vikky
July 13, 2012
want to delete programe file

i would like to know how to delete the programe file since system is not allowing for the same due to some Administration issue , pl advice how do i . msg is coming it is being used by another person // but it is not like that ....due to Administration Blocking i can not ... pl advice
DMCA.com