<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to process 2 latest file from a folder based on modified date in Talend Studio</title>
    <link>https://community.qlik.com/t5/Talend-Studio/How-to-process-2-latest-file-from-a-folder-based-on-modified/m-p/2271075#M48790</link>
    <description>&lt;P&gt;There are a few steps to this. I have created an example job which can be seen below....&lt;/P&gt; 
&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2019-08-06 at 11.18.03.png" style="width: 999px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009M7RE.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/130915i563F397D7DF319C9/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009M7RE.png" alt="0683p000009M7RE.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;First of all, use a tFileList to monitor your folder and retrieve CSV files. Using this component is described in the documentation.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;The next is a tJavaFlex. Create two columns for this; a filedate column (Date) and a filepath column (String). You need to convert the filename to a date and pass the filepath as normal. This is done in the MainCode section. The code I have used is below....&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt; 
&lt;PRE&gt;String filename = ((String)globalMap.get("tFileList_1_CURRENT_FILE"));
filename = filename.substring(4, filename.length()-4);

row1.filedate = routines.TalendDate.parseDate("yyyyMMddHHmmss", filename);
row1.filepath = ((String)globalMap.get("tFileList_1_CURRENT_FILEPATH"));&lt;/PRE&gt; 
&lt;P&gt;After that, the records are sent to a tHashOutput set with the "Append" option on.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;In the next subjob, you start with a tHashInput component. This is linked to the tHashOutput and has the same schema.&lt;BR /&gt;&lt;BR /&gt;Join that to a tSortRow component. My config is shown below...&lt;BR /&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2019-08-06 at 11.18.22.png" style="width: 999px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009M7RJ.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/145446i13B17157ECA4926A/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009M7RJ.png" alt="0683p000009M7RJ.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;This sorts the files by date.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;The next component is the tMap. This is used to filter only the two newest files. I do this by creating a "count" record in a tMap variable. This use the Numeric.sequence method. As the records pass through the tMap, they are assigned a number. The tMap output then filters the records which are allowed to be output to have a count less than 3. This can be seen below...&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2019-08-06 at 11.18.57.png" style="width: 999px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009M7RO.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/140951i334B41613661A756/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009M7RO.png" alt="0683p000009M7RO.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;After this, I have a tLogRow simply to show the result.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Note: I have just realised that the example is set up for the two oldest files. Just switch the tSortOrder component's sort order to asc to get the two newest.&lt;/P&gt;</description>
    <pubDate>Tue, 06 Aug 2019 11:28:42 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2019-08-06T11:28:42Z</dc:date>
    <item>
      <title>How to process 2 latest file from a folder based on modified date</title>
      <link>https://community.qlik.com/t5/Talend-Studio/How-to-process-2-latest-file-from-a-folder-based-on-modified/m-p/2271073#M48788</link>
      <description>&lt;P&gt;I have a scenario where I will have some set of files which gets created by some external system for every 10 minutes or so.How to process only the 2 latest file from all the files present in the folder sorted on file creation date/modified date in desc?&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Ex : C:/Sample/Incoming_Files -&amp;gt; Emp_YYYYMMDDHHMMSS is the file format&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Emp_20190801001534.csv&lt;/P&gt; 
&lt;P&gt;Emp_20190801041522.csv&lt;/P&gt; 
&lt;P&gt;Emp_20190801031555.csv&lt;/P&gt; 
&lt;P&gt;Emp_20190801001504.csv&lt;/P&gt; 
&lt;P&gt;Emp_20190801101517.csv&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;How to process the 2 latest file from the folder based om modified date?&lt;/P&gt; 
&lt;P&gt;Could someone please make it quick?&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Thanks,&lt;/P&gt; 
&lt;P&gt;Kiran Kumar&lt;/P&gt;</description>
      <pubDate>Sat, 16 Nov 2024 05:04:09 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/How-to-process-2-latest-file-from-a-folder-based-on-modified/m-p/2271073#M48788</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-11-16T05:04:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to process 2 latest file from a folder based on modified date</title>
      <link>https://community.qlik.com/t5/Talend-Studio/How-to-process-2-latest-file-from-a-folder-based-on-modified/m-p/2271074#M48789</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Make use of tfileproperties which will give you details of the modified date and time of file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;Ganshyam&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Aug 2019 10:25:23 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/How-to-process-2-latest-file-from-a-folder-based-on-modified/m-p/2271074#M48789</guid>
      <dc:creator>Ganshyam</dc:creator>
      <dc:date>2019-08-06T10:25:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to process 2 latest file from a folder based on modified date</title>
      <link>https://community.qlik.com/t5/Talend-Studio/How-to-process-2-latest-file-from-a-folder-based-on-modified/m-p/2271075#M48790</link>
      <description>&lt;P&gt;There are a few steps to this. I have created an example job which can be seen below....&lt;/P&gt; 
&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2019-08-06 at 11.18.03.png" style="width: 999px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009M7RE.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/130915i563F397D7DF319C9/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009M7RE.png" alt="0683p000009M7RE.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;First of all, use a tFileList to monitor your folder and retrieve CSV files. Using this component is described in the documentation.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;The next is a tJavaFlex. Create two columns for this; a filedate column (Date) and a filepath column (String). You need to convert the filename to a date and pass the filepath as normal. This is done in the MainCode section. The code I have used is below....&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt; 
&lt;PRE&gt;String filename = ((String)globalMap.get("tFileList_1_CURRENT_FILE"));
filename = filename.substring(4, filename.length()-4);

row1.filedate = routines.TalendDate.parseDate("yyyyMMddHHmmss", filename);
row1.filepath = ((String)globalMap.get("tFileList_1_CURRENT_FILEPATH"));&lt;/PRE&gt; 
&lt;P&gt;After that, the records are sent to a tHashOutput set with the "Append" option on.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;In the next subjob, you start with a tHashInput component. This is linked to the tHashOutput and has the same schema.&lt;BR /&gt;&lt;BR /&gt;Join that to a tSortRow component. My config is shown below...&lt;BR /&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2019-08-06 at 11.18.22.png" style="width: 999px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009M7RJ.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/145446i13B17157ECA4926A/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009M7RJ.png" alt="0683p000009M7RJ.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;This sorts the files by date.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;The next component is the tMap. This is used to filter only the two newest files. I do this by creating a "count" record in a tMap variable. This use the Numeric.sequence method. As the records pass through the tMap, they are assigned a number. The tMap output then filters the records which are allowed to be output to have a count less than 3. This can be seen below...&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2019-08-06 at 11.18.57.png" style="width: 999px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009M7RO.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/140951i334B41613661A756/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009M7RO.png" alt="0683p000009M7RO.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;After this, I have a tLogRow simply to show the result.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Note: I have just realised that the example is set up for the two oldest files. Just switch the tSortOrder component's sort order to asc to get the two newest.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Aug 2019 11:28:42 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/How-to-process-2-latest-file-from-a-folder-based-on-modified/m-p/2271075#M48790</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-08-06T11:28:42Z</dc:date>
    </item>
  </channel>
</rss>

