rename()

Declaration

int rename(const char* kcpOldName, const char* kcpNewName);

Description:

This function renames a file or directory specified by the null-terminated string "kcpOldName" to the name specified by "kcpNewName." The function returns 0 if successful. Otherwise, the function returns a negative value and and sets the value of errno to indicate an error.

Example

#include <cstdio>

int main()
{
    // Delete the local file
    int iRet = rename("XoaX.txt", "XoaXdotnet.txt");

    // Check whether or not some characters were written
    if (iRet != 0) {
        perror("Failed to rename file XoaX.txt");
    } else {
        printf("The file XoaX.txt was renamed.\n");
    }

    return 0;
}


Local Folder Before Run:





Local Folder After Run:



Output:

rename() Output