Copy and Move Files - Mule 4

The File connector can copy or move files or directories on demand. If you specify the sourcePath as a directory name, a directory is copied or moved. Otherwise if sourcePath is a file, only the file is copied or moved. If a file or directory already exists and overwrite is false, the FILE:FILE_ALREADY_EXISTS error occurs.

Example: Copy and Move Operations
<file:copy sourcePath="source.txt"
  targetPath="backup"
  overwrite="true|false"
  createParentDirectories="true|false"
  renameTo="renamed.txt"/>

<file:move sourcePath="source.txt"
  targetPath="backup"
  overwrite="true|false"
  createParentDirectories="true|false"
  renameTo="renamed.txt"/>

Notice the targetPath and renameTo parameters:

  • targetPath - The name of a directory into which the file is to be copied or moved. This path must point to a directory. If targetPath doesn’t exist, and neither does its parent, an attempt is made to create depending on the value of the createParentDirectories argument. If createParentDirectories is false, then FILE:ILLEGAL_PATH occurs.

  • renameTo - An optional parameter that renames the file as part of the operation. This parameter must be a file name, not a path. If this attribute is not provided, the original file name is retained.