Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
DrGenious
Creator
Creator

Delete files with timestamp rule

Hello everyone,

 

I have a directory where I put files every minute. I want this directory to delete the files  which are there over 8 days. How is this possible?

 

Thanks a lot.

Labels (2)
1 Solution

Accepted Solutions
TRF
Champion II
Champion II

Using tFileProperties you can access the mtime field which represents the last modification date for the file.

Then you just have to compare with actual datetime to decide to delete the file or not.

Here is the design:

tFileList--(iterate)-->tFileProperties--(main)-->tFlowToIterate--(OnComponentOk)--(If)-->tFileDelete

And here is the condition for the "If" trigger:

((TalendDate.getCurrentDate()).getTime() - (Long)globalMap.get("row1.mtime")) > (8 * 24 * 3600000)

This suppose the flow after tFileProperties is called "row1".

If not, you just have to adjust the condition with the real flow name.

View solution in original post

3 Replies
TRF
Champion II
Champion II

Using tFileProperties you can access the mtime field which represents the last modification date for the file.

Then you just have to compare with actual datetime to decide to delete the file or not.

Here is the design:

tFileList--(iterate)-->tFileProperties--(main)-->tFlowToIterate--(OnComponentOk)--(If)-->tFileDelete

And here is the condition for the "If" trigger:

((TalendDate.getCurrentDate()).getTime() - (Long)globalMap.get("row1.mtime")) > (8 * 24 * 3600000)

This suppose the flow after tFileProperties is called "row1".

If not, you just have to adjust the condition with the real flow name.

DrGenious
Creator
Creator
Author

@TRF thank you a lot really. 

 

I want to ask you also something if You know.

 

I create this CSV and I append this info inside :

pw.println(TalendDate.formatDate("yyyy-MM-dd HH:mm:ss", TalendDate.getCurrentDate()) + " , " + "Error in reading file: " + ((String)globalMap.get("tWaitForFile_2_FILENAME")) + " , " + "Error: " + input_row.errorMessage);

 

In this case which is one file but I want to delete rows from the CSV after 8 days, how can I do it? 

TRF
Champion II
Champion II

This is not the same question but the previous one may help you. For this one you have to read the file (tFileInputDelimited) then filter rows within a tMap using the appropriate comparison methods.
I strongly suggest you to try a little by yourself as you have the keys with the previous question (which could be marked as solved).