Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
mahitham
Creator II
Creator II

Help on deleting QVDs from the Folder dynamically

Hi,

Can any one please help me on below requirement.

I have a Daily refresh Extract app. By refreshing daily one QVD is generated in the Truncate folder like below.

But due to daily refresh the folder size is increasing. 

Can any one please help on writing the script for , how to keep the Today date qvd and last 5 Mondays QVDs in the folder by deleting remaining QVDs.

Please find the below attached qvd folder.

Truncate.png

Thanks in advance.

1 Reply
vunguyenq89
Creator III
Creator III

Hi,

You can do it with the following steps:

  • Loop through the list of QVD files in your folder. In each loop:
  • Extract date from file name
  • Check if the date is today or Monday within the last 5 weeks
  • If not, delete the file with Execute command 

Sample script as follows:

Set vQVD_Path = 'C:\Temp\QVDs';
Set vWeeks = 5; // How many Mondays you want to keep

For Each vFile in filelist ('$(vQVD_Path)\'&'\*.qvd')
	vFileName = SubField(vFile,'\',-1);
	vDay = Date(Date#(Left(vFileName,8),'YYYYMMDD'));
    vDayName = WeekDay(vDay);
    If Not((vDayName = 'mon' and vDay > Today() - vWeeks * 7)  or vDay = Today()) then
		Execute cmd.exe /C del "$(vFile)";
    EndIf;
Next vFile;

You will need to disable Standard mode in Qlik Sense (https://help.qlik.com/en-US/sense/November2019/Subsystems/Hub/Content/Sense_Hub/LoadData/disable-sta...) to be able to run the Execute command. Also make sure the Qlik Sense service account has permission to delete the QVD files.

Hope this helps!

BR,

Vu Nguyen