os.rename
Rename a file or move a file.
rename(oldName, newName)Examples
Rename a file and move it to another directory.
javascript
function main() {
let oldFileName = "output.txt"
let newFileName = "outputFiles/" + new Date().getTime() + "output.txt"
// let retRename = os.rename(oldFileName, newFileName)
// Log("retRename:", retRename) // the target directory outputFiles does not exist, so rename
// throws an exception
os.mkdir("outputFiles")
let retRename = os.rename(oldFileName, newFileName)
Log("retRename:", retRename)
// Output: retRename: true
}Returns
| Type | Description |
bool | Returns true when the operation succeeds; throws an exception on failure (can be caught with try...catch). |
Arguments
| Name | Type | Required | Description |
oldName | string | Yes | The name or path of the original file. |
newName | string | Yes | The name or path of the new file. |
See Also
Remarks
This function can be used to rename a file or move a file to another directory. If the directory of the new path does not exist, the operation will fail.