Type/to search
Built-in Functions
Global
Log
Market
Trade
Account
Futures
Exchange
IO
Network
Storage
Threads
TA
Talib
OS
os
os.open
os.fgets
os.fputs
os.mmap
os.getRootDir
os.listFiles
os.exists
os.remove
os.mkdir
os.rmdir
os.rename
os.stat
os.exit
File
ListFilesResult
FileStat
Structures
Built-in Variables and Constants
Conventions
Exchanges

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

TypeDescription

bool

Returns true when the operation succeeds; throws an exception on failure (can be caught with try...catch).

Arguments

NameTypeRequiredDescription

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.