Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
lmit
Creator II
Creator II

File delete

Hi All,

 

I have a zip files with dates as file name so i have to delete the files which are 5 days older to current date, how can i achieve this, i tried tfileproperties component from the forum which uses file creation date 

 

is there a way where i can use file name date for deletion?

 

Thanks in advance,

lmit 

Labels (2)
7 Replies
TRF
Champion II
Champion II

Into a tJava component, use TalendDate.addDate to get the current date minus 5 days and TalendDate.formatDate to format the result as expected and store the result to a global variable:

globalMap.put("theDate", TalendDate.formatDate("yyyyMMdd", TalendDate.addDate(TalendDate.getCurrentDate(), -5,"dd")));

Then, use a tFileList component to get all file with the desired mask:

 0683p000009M9sY.png

Finally, use tFileDelete to all corresponding files.

 

 

lmit
Creator II
Creator II
Author

Hi All,

 

Thanks TRF for your suggestion i did as your suggested but only one file is getting deleted not the other files which are greater than 5.

 

It should all the zip files which are greater than 5 days

 

Thanks,

lmit

TRF
Champion II
Champion II

If you need to delete files older than 5 days, you need to get all files, extract the date part from the filename, convert it into a date and compare the result to the current date minus 5 days.
Here is what the job should look like:
tFileList--(iterate)-->tJava--(If)-->tFileDelete
lmit
Creator II
Creator II
Author

Hi TRF,

Thanks for the reply but My file names have only date , I followed the process you said but still only one file is getting deleted.

Thanks,
Lmit
TRF
Champion II
Champion II

Share your job design with components settings and an example filename
lmit
Creator II
Creator II
Author

Hi TRF,

 

my file names will be 2020-03-10.zip

 

Please find the attachment for the job design.

 

in if link, the condition is 

context.comapredate >=1

 

Thanks,

lmit


delete.PNG
lmit
Creator II
Creator II
Author

Hi all,

Any suggestions on the below

Thanks in advance,
Lmit