fs_rename()
int fs_rename (const char *name_full_old, const char *name_full_new);
File | Called from | Code enabled by |
---|---|---|
| Application |
|
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
name_full_old
andname_full_new
must specify entries on the same volume.- If
path_old
andpath_new
specify the same entry, the volume will not be modified and no error will be returned. - If
path_old
specifies a file:path_new
must not specify a directory;- if
path_new
is a file, it will be removed.
- If
path_old
specifies a directory:path_new
must not specify a file- if
path_new
is a directory,path_new
must be empty; if so, it will be removed.
- 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.
- The file
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.