Karthi
Karthi

Reputation: 708

Delete files using pentaho

I want to know how to delete files based the creation date using a kettle job. I have a log folder which contains log files for last one year. But I want to keep only last week log files. The job should be deleting all the log files which are more than one week old. There is a delete file option in pentaho job. But how do we get file creation date and delete the files accordingly

Upvotes: 1

Views: 6867

Answers (1)

Marlon Abeykoon
Marlon Abeykoon

Reputation: 12465

You can do that in a transformation. Below shown is the steps required. enter image description here


1. Here you can get the filenames by providing the directory name in Get File Names step. (It gives additional info such as lastmodifieddate of file as a column)
2. Then you can write some java code to filter the filenames. eg: (today-7days) and send more than one week old filenames to next step.
3. Use Process Files to delete files. Select Operation as delete and Source filename field as filename. Finally you can call the transformation from a job in order to schedule it.

P.S If you don't like the java filter step You can also get today's date from Get System info step and you can reduce seven days from todays date in Calculator step then filter rows step can be used accordingly.

Upvotes: 3

Related Questions