fs_rename()

int  fs_rename (const  char  *name_full_old,
                const  char  *name_full_new);


File

Called from

Code enabled by

fs_api.c

Application

FS_CFG_API_EN and not FS_CFG_RD_ONLY_EN

Rename a file or directory.

Arguments

name_full_old

Old name of the entry.

name_full_new

New name of the entry.

Returned Value

0, if the entry is not renamed.

-1, if the entry is not renamed.

Notes/Warnings

  1. name_full_old and name_full_new must specify entries on the same volume.
  2. If path_old and path_new specify the same entry, the volume will not be modified and no error will be returned.
  3. If path_old specifies a file:
    1. path_new must not specify a directory;
    2. if path_new is a file, it will be removed.
  4. If path_old specifies a directory:
    1. path_new must not specify a file
    2. if path_new is a directory, path_newmust be empty; if so, it will be removed.
  5. The root directory may not be renamed.

Example

void  App_Fnct (void)
{
    int  err;
    .
    .
    .
                                                   /* See Note #1.    */
    err = fs_rename("sd:0:\\data\\file001.txt",    /* Rename file.    */
                    "sd:0:\\data\\old\\file001.txt");
    if (err != 0) {
        APP_TRACE_INFO(("Could not rename file."));
    }
    .
    .
    .
}

(1) For this example file rename to succeed, the following must be true when the function is called:

    • The file sd:0:\data\file001.txt must exist.
    • The directory sd:0:\data\old must exist.
    • If sd:0:\data\old\file001.txt exists, it must not be read-only.

If sd:0:\data\old\file001.txt exists and is not read-only, it will be removed and sd:0:\data\file001.txt will be renamed.