C Standard Libraries C++

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.

Local Folder Before Run:



Local Folder After Run:



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;
}

Output

rename() Output
 

© 2007–2024 XoaX.net LLC. All rights reserved.