Skip navigation
All People > Aurora_Gaimon > Aurora Gaimon's Blog > 2017 > April > 29

My first 30 Blog Post

Posted by Aurora_Gaimon Employee Apr 29, 2017

In previous post we learned how to delete a file. Today, I'd like to show how to make a copy of it. To make it simple, I will use kind of the same example.


Our file new is demoFile.csv which is located under testFolder.



We would like to make a new copy named demoFileCopy.csv under new location newTestFolder.


That can be easily achieved by using the methods File()  and copyFile().



Let's see a sample below:




1. Create a csv file and place in in a folder. In our example, I will use "c:\testFolder" and "demoFile.csv"




2. Create a simple process with a GEL script:

<gel:script xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary" 

<!--Location of the File -->
<core:new className="" var="oldLocation">
<core:arg type="java.lang.String" value="c:\testFolder\demoFile.csv"/>

<!-- New Location of the File -->
<core:new className="" var="newLocation">
<core:arg type="java.lang.String" value="c:\newTestFolder\demoFile.csv"/>

<!-- Copy File -->
<core:invokeStatic className="com.niku.union.utility.FileUtils" method="copyFile">
<core:arg type="" value="${oldLocation}"/>
<core:arg type="" value="${newLocation}"/>

<core:new className="" var="File">
<core:arg type="java.lang.String" value="c:\testFolder\demoFile.csv"/>



3. Execute process:



4. Check new location folder. We can also verify file has been created new time stamp as per process execution:




** Note: If you check content, you will see it's been also copied without issues.



I'm pretty sure other developers may have other tricks or ways. I just wanted to use something easy, clear and re-usable.



Related posts:



If you need help with GEL scripting, engage CA Services or ask questions in CA Communities.


That’s all. Thanks for reading until here. Did you like it? Please, don’t be shy and share it.