6.18.38 rename Function

Renames the specified file.

Attention: This function is not implemented by MPLAB XC8.

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>

int main(void)
{
  if (rename("myfile.txt","newfile.txt") != 0)
    printf("Cannot rename file");
  else
    printf("File renamed");
}

Example Output

File renamed