rename
int  remove ( const char * oldname , const char * newname );
stdio.h
  cplusplus.com  

Rename a file or directory.
  Renames the file or directory specified by oldname to newname.
  If oldname and newname specify different paths the file is moved.

Parameters.

oldname
Path and name of the file to be renamed or moved. This file must exist and we must have write access to it.
newname
New path and name for the file. This filename must not be the same of an existing one.

Return Value.
  If the file is succesfully renamed/moved a 0 value is returned.
  On error a non-zero value is returned and the errno variable is set to the corresponding error code that can be printed using perror.

Portability.
  Defined in ANSI-C.
  Some systems do not allow to move directories.

Example.

/* rename example */
#include <stdio.h>

main ()
{
  int result;
  char oldname[] ="oldname.txt";
  char newname[] ="newname.txt";
  result= rename( oldname , newname );
  if (result != 0 )
    perror( "Error renaming file" );
  return 0;
}
  If the file example.txt existed before the execution and we meet all requirement for calling this function the file will be renamed, otherwise a message similar to this will be written to stderr:
Error renaming file: Pemission denied

See also.
  remove


© The C++ Resources Network, 2000