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

How delete files in folder when max. count is reached?

Hi,

I have a folder in which my job will produce a file. This folder should only contain max. 10 files, so if the folder contains already 10 files, I need to delete the oldest file first, before my job can produce a file.

I have started with a tFileList --> tFileProperties and then into a tJava component, but it makes no sense 🙂 I do not need to iterate over all item, I need to get a count of files and if > 10 delete the oldest.

Any suggestion?

Thanks

Labels (2)
2 Replies
Anonymous
Not applicable

Hello,

Normally, the global variable ((Integer)globalMap.get("tFileList_1_NB_FILE"))) is used in the next subjob, eg:

tfilelist--iterate--->....

|onsubjobok

tJava

 

on tJava:

System.out.println("Total file count is: " + ((Integer)globalMap.get("tFileList_1_NB_FILE")));

You will get the total no. of files and make use of RunIf connection type to delete files.

How do you judge the old files that doesn't be needed anymore? By date? Are your files in the folder named by date?

Best regards

Sabrina

 

 

olja
Contributor
Contributor
Author

Hi, thanks for the answer. The oldest files should be deleted, what is the runIf Connection? Actually I am deleting files in the tJava but is not working as expected. Can you explain your advice with the runIf connection.

 

Thanks