Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

How to get latest files

How to get the latest file. when we run history. Can anyone please help to sort it out.

Labels (2)
1 Solution

Accepted Solutions
TRF
Champion II
Champion II

Just have to change the tJava code to use BigInteger instea of Int:

BigInteger dateFile = new BigInteger(((String)globalMap.get("tFileList_2_CURRENT_FILE")).replaceAll("^.*_", "").replace(".psv", ""));

if ((BigInteger)globalMap.get("maxDate") == null || dateFile.compareTo((BigInteger)globalMap.get("maxDate")) == 1) {
	globalMap.put("maxDate", dateFile);
	globalMap.put("lastFile", (String)globalMap.get("tFileList_2_CURRENT_FILE"));
}

 

View solution in original post

16 Replies
TRF
Champion II
Champion II

Have a look to tFileList component options to sort files based on chronological order with older first.
Anonymous
Not applicable
Author

There is only modified in tfilelist. 

In my scenario I'm downloading all the history files in job server, but based on filedate it should process only latest date file.

Eg: 1.Customersdata_20180126.psv

       2.Customersdata_20180201.psv

       3.Customersdata_20171231.psv

We have to process only  2.Customersdata_20180201.psv file which is latest

 

Thanks,

Venkat

 

TRF
Champion II
Champion II

Same answer based on filename.
Memorize the 1rst name using a global variable then reuse the variable in the next subjob to get the file.
Anonymous
Not applicable
Author

Can you please explain in detail, because file names may vary.

manodwhb
Champion II
Champion II

first put in the memory that the pattern of the file. and call the same pattern in to tFilelist.

 

1) pattern would be like this globalMap.put("pattern", "Customersdata_"+ TalendDate.getDate("yyyyMMdd") + pattern_suffixe);

2) use the same paatern to get see the below screen shot.0683p000009Ls8S.png

 

 

 

--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.

TRF
Champion II
Champion II

Hi,

Stricly based on your filenames, here is a complete solution to get the latest file:

0683p000009LsLy.png

tFileList is configured with the filemask "*.psv" and here is the content of the tJava component:

 

 

// get the date contained into the current filename
int dateFile = Integer.parseInt(((String)globalMap.get("tFileList_2_CURRENT_FILE")).replaceAll("^.*_", "").replace(".psv", ""));

// if there is no "maxDate" known or the current date is > to "maxDate" then the current date becomes the "maxDate"
if ((Integer)globalMap.get("maxDate") == null || dateFile > (Integer)globalMap.get("maxDate")) {
globalMap.put("maxDate", dateFile);
globalMap.put("lastFile", (String)globalMap.get("tFileList_2_CURRENT_FILE"));
}

Now you can get the filename using the global variable called "lastFile" using the following syntax (for example to populate the Filename field of a tFileInputDelimited or tFileInputFullRow component):

(String)globalMap.get("lastFile")

This example is based on your input and works fine.

You may have to adapt it to your case.

Don't forget to mark your case as solved as soon as it is ok for you (Kudo also accepted).

Anonymous
Not applicable
Author

Hi,

I'm very thankful for your detailed explanation.

My filename is coming like this

 

Good_Customersdata_20171231_20171231092635.psv

In this file 20171231092635 is date with timestamp I can to check based on this.

Please help me to sort it 

TRF
Champion II
Champion II

Just have to change the tJava code to use BigInteger instea of Int:

BigInteger dateFile = new BigInteger(((String)globalMap.get("tFileList_2_CURRENT_FILE")).replaceAll("^.*_", "").replace(".psv", ""));

if ((BigInteger)globalMap.get("maxDate") == null || dateFile.compareTo((BigInteger)globalMap.get("maxDate")) == 1) {
	globalMap.put("maxDate", dateFile);
	globalMap.put("lastFile", (String)globalMap.get("tFileList_2_CURRENT_FILE"));
}

 

Anonymous
Not applicable
Author

It is showing BigInt cannot be resolved.