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: 
prasanthkesana
Contributor
Contributor

How to delete files older than 48 hours

Hi

I have a requirement to delete old files based on date timestamp,

I found the component tFileProperties to fetch file properties

below is the sample job i have created by using the talend components

tFileList---iterate-- > tFileProperties ---main--->tMap-------main--->tfileDelte

On tMap schema editor i have used condition to check mtime in expression

((TalendDate.getCurrentDate()).getTime() - (Long)row1.mtime) > (8 * 24 * 3600000) to delete files based on above condition.

Can you please suggest any solution as per my requirement.

Thanks,

Prasanth

Labels (2)
12 Replies
prasanthkesana
Contributor
Contributor
Author

Hi

i have created new file and run the job,

If i used this expression ((TalendDate.getCurrentDate()).getTime() - (Long)row1.mtime) > (2 * 24 * 3600000) files are not deleting.

 

For this expression ((TalendDate.getCurrentDate()).getTime() - (Long)row1.mtime)+86400000 > (31* 24 * 3600000) all files are deleting at once. I found this while searching for the suitable expression it will delete before 31 days old files but deleting all.

 

 

 

Thanks,

Prasanth

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

cmills
Contributor
Contributor

I had to replace the math with:

Long.valueOf(2) * Long.valueOf(24) * Long.valueOf(3600000)

 

As the int values kept going negative due to size.

ykuwar
Contributor III
Contributor III

Hello @Shicong Hong​ ,

 

1] Delete files older than 48 hrs

condition in tMap - > ((TalendDate.getCurrentDate()).getTime() - (Long)row1.mtime) > (2 * 24 * 3600000)

 

2] The file name of tFileDelete component should be:

((String)globalMap.get("tFileList_1_CURRENT_FILEPATH"))

 

Thanks for the solution this works for me!