How to Copy a File with Groovy

Document created by rich_patterson Employee on Mar 6, 2017Last modified by Adam Arrowsmith on Mar 17, 2017
Version 2Show Document
  • View in full screen mode

The following Groovy snippet creates a copy of a file. This can be used within a Data Process Custom Scripting step for example.

 

sourceFile and targetFile are both strings that represent the files. In testing with Java 8, the filenames were fully qualified, containing full directory names.

 

java.nio.file.Files.copy(
       new java.io.File(sourceFile).toPath(),
       new java.io.File(targetFile).toPath(),
       java.nio.file.StandardCopyOption.REPLACE_EXISTING,
       java.nio.file.StandardCopyOption.COPY_ATTRIBUTES );

Attachments

    Outcomes