This is the legacy 4D documentation web site. Documentations are progressively being moved to developer.4d.com

Home

 
4D v19.8
file.copyTo( )

file.copyTo( ) 


 

file.copyTo ( destinationFolder {; newName}{; overwrite} ) -> Result 
Parameter Type   Description
destinationFolder  Object in Destination folder
newName  Text in Name for the copy
overwrite  Longint in fk overwrite to replace existing elements
Result  Object in Copied file

The file.copyTo( ) method copies the File object (source file) into the specified destinationFolder

The destinationFolder must exist on disk, otherwise an error is generated.  

By default, the file is copied with the name of the original file. If you want to rename the copy, pass the new name in the newName parameter. The new name must comply with naming rules (e.g., it must not contain characters such as ":", "/", etc.), otherwise an error is returned.

If a file with the same name already exists in the destinationFolder, by default 4D generates an error. You can pass the fk overwrite constant in the overwrite parameter to ignore and overwrite the existing file:

Constant Value Comment
fk overwrite 4

Overwrite existing elements, if any

 

Returned object

The method returns the copied File object.

Example  

You want to copy a picture file from the user's document folder to the database folder:

 C_OBJECT($source;$copy)
 $source:=Folder(fk documents folder).file("Pictures/photo.png")
 $copy:=$source.copyTo(Folder("/PACKAGE");fk overwrite)



See also 

COPY DOCUMENT

 
PROPERTIES 

Product: 4D
Theme: File and Folder

This command can be run in preemptive processes

 
PAGE CONTENTS 
 
HISTORY 

Created: 4D v17 R5

 
ARTICLE USAGE

4D Language Reference ( 4D v19)
4D Language Reference ( 4D v19.1)
4D Language Reference ( 4D v19.4)
4D Language Reference ( 4D v19.5)
4D Language Reference ( 4D v19.6)
4D Language Reference ( 4D v19.7)
4D Language Reference ( 4D v19.8)