Clarity

 View Only
  • 1.  Rename file using GEL script?

    Posted Dec 04, 2015 11:27 AM

    I've seen in an older post that it is possible to rename a file using a GEL script.  Does anyone have a code example I could look at?



  • 2.  Re: Rename file using GEL script?
    Best Answer

    Posted Dec 04, 2015 01:24 PM

    Here is one way.

     

     

    <?xml version="1.0" encoding="utf-8"?>
    <gel:script
        xmlns:core="jelly:core"
        xmlns:log="jelly:log"
        xmlns:util="jelly:util"
        xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    
        <gel:log>Start this Script</gel:log>
        
        <!-- Define a set of file names -->
        <core:set var="fileNameOne" value="gel\fileNameOne.txt"/>
        <core:set var="fileNameTwo" value="gel\FileNameTwo.txt"/>
        
        <gel:log>fileNameOne ${fileNameOne}</gel:log>
        <gel:log>fileNameTwo ${fileNameTwo}</gel:log>
        
        <!-- create to java.io.File objects -->
        <util:file var="fileOne" name="${fileNameOne}" />
        <util:file var="fileTwo" name="${fileNameTwo}" />
        
        <!-- see which ones exists -->
        <util:available file="${fileOne}">
            <gel:log>${fileNameOne} file is available</gel:log>
        </util:available>
        
        <util:available file="${fileTwo}">
            <gel:log>${fileNameTwo} file is available</gel:log>
        </util:available>
        
            <!-- Rename the file -->
        <gel:log>
            Rename the file ${fileOne.renameTo(fileTwo)}
        </gel:log>
        
            <!-- now see if the rename file exists -->
        <util:available file="${fileTwo}">
            <gel:log>${fileNameTwo} file is available</gel:log>
        </util:available>
        
        <gel:log>End this Script</gel:log>
    
    </gel:script>
    

     

     

    So I have my text file that I want to rename.

     

     

    I run the gel script and check for the renamed file.

     

    V/r,

    Gene