Renaming a File

Go to the Navigation pageHelpExitBackNext

The rename() Function
The rename() function changes the name of an existing disk file.
 
Syntax
The function prototype is in STDIO.H as follows:

int rename(const char *oldname,
           const char *newname);
 
Arguments
The filenames pointed to by oldname and newname follow the rules given earlier in this unit. The only restriction is that both names must refer to the same disk drive; you cannot "rename" a file to a different disk drive.
 
Return Value
The function rename() returns 0 on success, or -1 if an error occurs. Errors can be caused by the following conditions (among others):
 
The file oldname does not exist.
A file with the name newname already exists.
You try to rename to another disk.