Gadi
Gadi

Reputation: 53

Talend - delete files older then X days

How to delete contents of the folder older then x days in Talend job?

I have thought about retrieving that attribute from rFilesList (could not find) or passing unix command to a system (less preferable way as you have less control).

Thank you!

P.S. The issue solved

Upvotes: 1

Views: 2946

Answers (3)

Revathi Daggu
Revathi Daggu

Reputation: 64

Write a script to remove files over X days. and call the script from tSystem component : More about tSystem : https://help.talend.com/display/TalendOpenStudioComponentsReferenceGuide521EN/19.4+tSystem

Upvotes: 0

Gadi
Gadi

Reputation: 53

My solution (based on a link above): tFileList->iterate->tFileProperties (reads the file from previous step, ((String) globalMap.get ( "tFileList_1_CURRENT_FILEPATH")) )-> tMap has 2 outputs, based on mtime condition:

  1. Files to delete: (TalendDate.getCurrentDate().getTime()-row3.mtime)/(24*60*60*1000) > 2
  2. Files to keep: (TalendDate.getCurrentDate().getTime()-row3.mtime)/(24*60*60*1000) <=2

tFileDelete that deletes filesToDelete.filename

Upvotes: 1

Th&#233;o Capdet
Th&#233;o Capdet

Reputation: 1062

You can use a "tfilelist" coupled with a "tfileproperties". The variable mtime or mtime_string can help you.

Here there is a page that explain a little bit (but it's in french so you can google trad if you want) :

HERE

Upvotes: 1

Related Questions