Skip to content

Copy File

Type: copy-file  ·  Package: Filesystem Activities v1.0.6  ·  Output: string

Copies a file from a source path to a destination path, leaving the original in place. Use it to back up a file before changing it, duplicate a template, or distribute a document to several folders.

Copies the file at source to destination.

  • Destination: destination is the full path of the new file (folder + name), not just the folder. To keep the name, use pathJoin(destinationFolder, fileName(source)).
  • Folders: if the destination folder does not exist, it is created (with any intermediate ones).
  • Overwriting: by default it does not overwrite: if the destination exists, the activity fails (unless you set overwrite = true).
  • Files only: it copies one file; to copy a whole folder, list it with List Files and copy each file.
ParameterTypeDefaultDescription
sourcestring—Path of the source file.
destinationstring—Full path of the destination file (folder + name).
ParameterTypeDefaultDescription
overwriteboolfalseReplace the destination if it already exists.

Returns a string with the destination path of the copied file (as you gave it in destination).

MessageCause and fix
Could not find file '…'.The source file does not exist. Check it first with File Exists.
The file '…' already exists.The destination exists and overwrite is false. Set overwrite = true or use a unique name (for example with the date).
The process cannot access the file '…' because it is being used by another process.The source or destination is open in another program.
Access to the path '…' is denied.No permission on the source or the destination folder.
'source' is required. / 'destination' is required.The parameter’s expression evaluated to null.

Back up a file with the date in its name and log where it went:

Copy File source = "C:/data/master.xlsx" destination = "C:/backups/master_" + today().ToString("yyyyMMdd") + ".xlsx" overwrite = true → output: backup
Log message = "Backup created at " + backup