Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik and ServiceNow Partner to Bring Trusted Enterprise Context into AI-Powered Workflows. Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
Richard_Norris
Contributor III
Contributor III

Delete old files?

I have a process that generates a timestamped report, "YY-MM-DD-hhmm Reportname.pdf" on OneDrive, and it works great. But what I want to do, is add another block, to delete older files. 

I guess I probably need a 'check if file exists block' first, but my real issue is, how do I say, 

delete files matching "YY-MM-DD (of today minus 7 days) *WILDCARD* Reportname.pdf". 

So if I have

25-03-07-12:45pm Filename.pdf

25-03-07-16:22pm Filename.pdf

25-03-07-22:13pm Filename.pdf

and I run it on the 14th, it deletes all three of those files....?

Labels (3)
2 Replies
Richard_Norris
Contributor III
Contributor III
Author

I solved the first issue I was having, which was getting the date for seven days ago. Seems that the syntax is 

"now - 7 day"

(Not days). So that's pretty cool. If I create a fake file with the name of the exact right timestamp (quite trivial to do as it takes exactly 50 seconds to run the script end to end) it deletes it just fine, with the conditional block. Now I just have to try and work out if there's a wildcard character to catch all files from that day rather than just ones that match down to the minute. 

 

Seems like possibly the StartsWith(File.Name, 'Report_') might be the way to do it

salmankojar
Partner - Creator II
Partner - Creator II

Hi @Richard_Norris  Please find the attached json file as per your requirement it will only delete files older than 7 days from current date. i have kept the filenames in my storage as per your naming and it is working fine. try this it will work.