File.copy_to()
The copy_to()
method has two possible signatures:
file.copy_to(destination as File, overwrite as Boolean) as Boolean
file.copy_to(destination_path as Text, overwrite as Boolean) as Boolean
Copies this File
object’s file to the specified destination
.
Parameters
destination
.File
orText
. This parameter specifies the folder that will become the new parent folder of the file to be copied. Ifdestination
is aText
object then it may be either a relative path (relative to the currently executing script) or an absolute pathoverwrite
.Boolean
. If thisFile
object is a folder anddestination
contains (at its top level) an identically named folder andoverwrite
isTrue
then the folder withindestination
will be deleted before the copy is done. Similarly, if thisFile
object is a file anddestination
contains an identically named file at its top level andoverwrite
isTrue
then the file atdestination
will be deleted prior to the copy operation. Ifoverwrite
isFalse
then no files will be deleted/overwritten
Returns
True
if the copy was successful,False
if it fails
Notes
Text
paths use forward slashes (/
) as separators- Absolute paths begin with a forward slash, relative paths do not
Example
var source = File("/Users/garry/Desktop/test.txt")
source.copy_to("/Users/garry/Downloads", False) # Copy the file to the Downloads folder.
var destination = File("/Users/garry/Pictures/My Folder")
source.copy_to(destination, False)