File:copy(filename) method

Copies the file physically on the disk to the specified filename.

Warning

  • This operation will block program flow execution.
  • Use File.copytask() to copy the file asynchronously.

Parameters

filename

A string representing the destination filename.
If the filename contains a path, the path must already exist. If the destination file exists, the function will fail.

Return value

Returns a boolean value indicating if the operation succeeded.

Example

local file = sys.File("test.txt"):open("write") file:writeln("Hello World !") file:close() -- outputs false : cannot copy "test.txt" to "test.txt" print(file:copy("test.txt"))