Clarity

 View Only
  • 1.  Read two files in a directory with same names and one having timestamp

    Posted Oct 01, 2019 06:59 AM
    ​Hi ,

    I would like to read two files in a directory with nearly same names where one has timestamp included in the name.

    Eg: File 1: Magic2PPM
    File 2 : Magic2PPM_ddmmyyy

    Please advice me how to read files like these.

    Regards,
    Vinay


  • 2.  RE: Read two files in a directory with same names and one having timestamp

    Posted Oct 01, 2019 09:22 AM
    I think you will need to describe what you want to do with the files / what are the files / what does it have to do with your Clarity system and so on...


  • 3.  RE: Read two files in a directory with same names and one having timestamp

    Posted Oct 01, 2019 09:55 AM
    There are few files in other interface. We import those files which have the data .That data is  needed to be read and should be inserted into an intermediate table​


  • 4.  RE: Read two files in a directory with same names and one having timestamp
    Best Answer

    Posted Oct 01, 2019 10:06 AM
    OK so the solution is not necessarily* a "Clarity solution" if all you need to do is put some data from a file into a database table - and there are many ways of doing that, I would suggest that the best way for you to do it would be whichever technical way you (or your organisation) are most comfortable with or capable of.

    (* for example you could build a locally running routine on your sever that looks for files and uploads the contents of that file to a database table - no "Clarity" involved there)

    Other considerations you might have are whether this is a one-off process or a regular interface (and if regular, how regular - for example if its "once a month" you might choose a manual or semi-manual process, if it is "several times every day" you would expect a fully automated process).



  • 5.  RE: Read two files in a directory with same names and one having timestamp

    Posted Oct 14, 2019 12:11 AM
    Hi Vinay,

    If you need solution in GEL, this might be helpful
    <core:set value="Magic2PPM" var="requiredFileName"/>
    
    <core:set value="${requiredFileName.length()}" var="fileNameLength"/>
    
    //getting list of files from given directory using JAVA
    <core:invokeStatic className="java.lang.Runtime" method="getRuntime" var="javaRuntime"/>
    <core:new className="java.io.File" var="f">
    	<core:arg type="java.lang.String" value="##YOUR FOLDER PATH##"/>
    </core:new>
    <core:invoke method="list" on="${f}" var="fileNames"/>
    
    <core:if test="f.exists() != false and f.isDirfcectory() != false">
    	//Looping for each file in directory
    	<core:forEach begin="0" end="${fileNames.size()}" indexVar="i" items="${fileNames}" var="record">
    		<core:set value="${fileNames[i]}" var="currentFileName"/>
    		<core:set value="${currentFileName.substring(0,fileNameLength)}" var="currentFileNameStarting"/>
    		
    		//Comparing required file name with file name in directory
    		<core:if test="${currentFileNameStarting == requiredFileName}">
    			##YOUR CODE GOES HERE##
    		</core:if>
    	</core:forEach>
    </core:if>