If oldname and newname specify different paths and this is supported by the system, the file is moved to the new location.
This is an operation performed directly on a file; No streams are involved in the operation.
Parameters
- oldname
- C string containing the name of the file to be renamed and/or moved. This file must exist and the correct writing permissions should be available.
- newname
- C string containing the new name for the file. This shall not be the name of an existing file; if it is, the behavior to be expected depends on the running environment, which may either be failure or overriding.
Return value
If the file is successfully renamed, a zero value is returned.On failure, a nonzero value is reurned and the errno variable is set to the corresponding error code. Error codes are numerical values representing the type of failure occurred. A string interpreting this value can be printed to the standard error stream by a call to perror.
Example
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
If the file oldname.txt could be succesfully renamed to newname.txt the following message would be written to stdout:
File successfully renamed
Otherwise, a message similar to this will be written to stderr:
Error renaming file: Permission denied
See also
| remove | Remove file (function) |
