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: 
Not applicable

How to Clean Reports from a folder

Hi Experts,

I have created a Report

Report Name :- Sales_Report_Details

It will run daily on Date base and Every day report will store in Particular folder

for Example If Report runs on 10th May then it will Store as Sales_Report_Details_10th_May  in folder D:\Spraj\Desktop\Sales_Details\Reports

If Report runs on 11th May then it will Store as Sales_Report_Details_11th_May  in folder D:\Spraj\Desktop\Sales_Details\Reports


My Question is

I want to show only Last Week's Reports rest of the reports should be clear(Vanish)


Example:- If My Report is Running from May 1st and Today Date is 11th May, folder should contain only Last 7 Days Reports

i.e May 5th to May 11th Rest of the reports (May 1st to may 4th) should not be Appear in the folder


Is there any solution to resolve this Issue. Some one can please help me on this


Thank you,

Swarupaa




1 Reply
Anonymous
Not applicable
Author

Hi Swarup Raj,

You could get the list of files from your folder, get the name of the older ones an then use the execute function to call the dos del command to remove them:

/**************************************************************************************

* Variable Definition

**************************************************************************************/

SET vPath = 'Full path to your report folder here';

SET vFiles = '';

/****Load each file inside your derectory*********/

For Each file in FileList('$(vPath)'&'*.txt'); //Change the *.txt for your file extension

  SET vFiles = $(file),$(vFiles);

NEXT file;

/****Get the old the files older than 7 days*******/

FileList:

LOAD

  RowNo() as ID,

  SubField('$(vFiles)', ',') as File

AutoGenerate (1);

NoConcatenate

FilesToDelete:

LOAD

  chr(39) & Concat(File, chr(39)&','&chr(39)) & chr(39) as FileList

Resident FileList

Where ID > 7 and Len(File) > 0;

LET vFilesToDeleteList = Peek('FileList', 0, 'FilesToDelete');

/******Remove files*****************/

FOR Each i in $(vFilesToDeleteList)

  EXECUTE CMD.EXE /C del "$(i)";

NEXT

DROP Table FileList;

And in your script editor allow to run the command:

foto.png

Just, keep in mind that this will delete your files from your folder, and you won't be able to recover them.

Regards,

-- Karla