Home C-tutorials C file rename

Related Tutorials


 
 

Share on Google+Share on Google+

C file rename

Advertisement
This section illustrates you to rename a file in C. You can see in the given example that we want to replace the name of the text file MYFILE.txt with HELLO.txt.

C file rename

     

This section illustrates you to rename a file in C. You can see in the given example that we want to replace the name of the text file MYFILE.txt with HELLO.txt. For this, we have used the library function rename() which renames the file MYFILE.txt to HELLO.txt. In case if the file some how, not be renamed, the function perror() prints the error message.

Here is the code:

RENAMEFI.C

#include <stdio.h>
int main() {
  int renameFile=0;
  renameFile=rename("MYFILE.txt""HELLO.txt");
  if (renameFile!=0)
  perror("Error in renaming file.");
  return 0;
}

When you run the above example, the file MYFILE.txt is renamed to HELLO.txt. File MYFILE.txt should be placed where your RENAMEFI.C File is present.

Download Source Code:

 

Advertisement

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

Discuss: C file rename   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:2
bandan
December 22, 2011
physics

very help full;
N Nagaraj
January 9, 2013
not working

rename() function is not working
DMCA.com