Clarity

  • 1.  Gel

    Posted Jun 11, 2015 04:55 PM

    Hello,

     

    Is it possible read a file by part of its name? I have a situation where the file includes time info and that can be different every day. I need to read the file skipping the time info at the end.

     

    Is this possible? Please advice.

     

    Thank you,

    Rajani.



  • 2.  Re: Gel

    Posted Jun 11, 2015 06:15 PM

    The readFile tag requires a specific filename, it doesn't accept wildcards or patterns or other methods for deriving filenames so that needs to be done another way.

     

    This might help as an example to work from.

     

    My demo files:

    C:\Clarity\virtual\bin>dir \Clarity\temp\inp*
    Volume in drive C has no label.
    Volume Serial Number is E28D-6B14

     

    Directory of C:\Clarity\temp

     

    11/06/2015  16:55            74,791 inputdata.1.txt
    11/06/2015  16:55            74,791 inputdata.2015-05-24.txt
    11/06/2015  16:55            74,791 inputdata.txt
                   3 File(s)        224,373 bytes
                   0 Dir(s)   2,817,380,352 bytes free

     

    C:\Clarity\virtual\bin>

     

    filelist.gel:

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

        <!-- note the tag name is all lower case, and the pattern is a regex expression, and you can choose to search recursively or not -->
        <gel:filelist var="files" dir="/Clarity/temp" pattern=".*inputdata.*\.txt" recurse="false" />
        <gel:out>ArrayList&lt;>: ${files}, files[1]: ${files[1]}</gel:out>

    </gel:script>

     

    Execution results:

    C:\Clarity\virtual\bin>gel filelist.gel

     

    ArrayList<>: [inputdata.1.txt, inputdata.2015-05-24.txt, inputdata.txt], files[1]: inputdata.2015-05-24.txt

     

    C:\Clarity\virtual\bin>

     

    You can now use the name/names of your choice as inputs to the filename parameter of the readFile tag.



  • 3.  Re: Gel
    Best Answer

    Posted Jun 12, 2015 02:09 AM

    Not sure of your requirement but if you are looking for say the latest file in the folder, you can do it like this:

     

    <?xml version="1.0" encoding="utf-8"?>
    <gel:script
        xmlns:core="jelly:core"
        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 GetLatestFile Script</gel:log>
       
        <core:set var="logPath" value="D:\\clarity\\logs"/>
        <gel:log>LogPath = ${logPath}</gel:log>
       
        <core:new className="java.io.File" var="logDir" >
            <core:arg type="java.lang.String" value="${logPath}" />
        </core:new>
        <core:if test="${logDir.isDirectory()}" >
            <core:invoke method="listFiles" on="${logDir}" var="logFiles" />
            <gel:log>Found ${size(logFiles)} log files in ${logPath}</gel:log>
    
            <core:if test="${size(logFiles) &gt; 0}">
                <core:set var="lastModifiedFile" value="${logFiles[0]}"/>
                <core:forEach items="${logFiles}" var="file">
                        <core:if test="${lastModifiedFile.lastModified() &lt; file.lastModified()}">
                            <core:set var="lastModifiedFile" value="${file}"/>
                        </core:if>
                </core:forEach>
                    <gel:log>The latest file is ${lastModifiedFile.getAbsolutePath()}</gel:log>
            </core:if>
        </core:if>
       
        <gel:log>End GetLatestFile Script</gel:log>
    
    </gel:script>
    
    

     

    My log files:

     

     

    The gel script results.

     

     

    V/r,

    Gene



  • 4.  Re: Gel

    Posted Jun 16, 2015 12:43 PM

    Thank you, reading the latest file will work for me.