File:copytask(filename, [function]) method

Copies the file to a new one with the specified filename, asynchronously (without blocking program execution flow)

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.

[function]

An optional callback function that will be called periodically during the copy operation to get progress information. This function takes two parameters :

  • The first argument is the total bytes to be copied
  • The second argument is the number of bytes that have been copied

Return value

Returns a Task that will return a boolean value indicating if the operation succeeded.

Example

local console = require "console" local file = sys.File("big_video.mkv") file.step = 0 local function progress(total, done) local percentage = (done*100)/total if percentage / 10 > file.step then file.step = percentage / 10 + 1; console.write("■") end end console.write("Copying file... ") file:copy("big_video_copy.mkv", progress):wait()