Renames the specified file.
Include
<stdio.h>
Prototype
int rename(const char *old, const char *new);
Arguments
old
|
pointer to the old name |
new
|
pointer to the new name |
Return Value
Return 0 if successful; otherwise, returns a non-zero value.
Remarks
The old name must exist in the current working directory. The new name must not already exist in the current working directory.
Example
#include <stdio.h> /* for rename, printf */
int main(void)
{
if (rename("myfile.txt","newfile.txt") != 0)
printf("Cannot rename file");
else
printf("File renamed");
}
Example Output
File renamed