Aurora_Gaimon

CA PPM: How to copy files with GEL

Blog Post created by Aurora_Gaimon Employee on 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:

 

Steps:

 

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" 
xmlns:core="jelly:core"
xmlns:util="jelly:util">


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

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


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

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


</gel:script>

 

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.

Outcomes