Skip to main content
Announcements
Qlik Introduces a New Era of Visualization! READ ALL ABOUT IT
cancel
Showing results for 
Search instead for 
Did you mean: 
ASEDavidSu
Contributor III
Contributor III

How to delete history Excel files (past four days)in the folder when I reload

Dear Experts,

As the subject above, how to delete Excel history files(past four days)from the "test2" folder when I reload

Bellow is my macro and script:

ASEDavidSu_0-1662968739604.png

IF Date(FileTime(),'YYYY/MM/DD') = Date(Today(),'YYYY/MM/DD') OR Date(Today(),'YYYY/MM/DD')-1 OR Date(Today(),'YYYY/MM/DD')-2 OR Date(Today(),'YYYY/MM/DD')-3 OR Date(Today(),'YYYY/MM/DD')-4 then

QVDEVERYDAYDATAFiles:
LOAD [File Name],
QVDFileTime as noupdateFileTime,
FileSize,
Timestamp(DATE(qvdFileTime ,'YYYY/MM/DD PM hh:mm:ss'),'YYYY/MM/DD') as updateFileTime,
Timestamp(DATE(qvdFileTime ,'YYYY/MM/DD hh:mm:ss'),'YYYY/MM/DD hh:mm:ss') as UpdateFileTime


FROM
[D:\test2\*.xlsx]
(ooxml, embedded labels, table is QVDDATA);

ELSEIF Date(FileTime(),'YYYY/MM/DD') <> Date(Today(),'YYYY/MM/DD') OR Date(Today(),'YYYY/MM/DD')-1 OR Date(Today(),'YYYY/MM/DD')-2 OR Date(Today(),'YYYY/MM/DD')-3 OR Date(Today(),'YYYY/MM/DD')-4 then

let vxlsxfile = 'D:\test2\*.xlsx';
let filedeleted = (DeleteFile('$(vxlsxfile)')=-1);
TRACE File deleted $(filedeleted);

ENDIF

--------------------------------------------------------------------------------------------------------------------------------------------------------------

The macro was no problem and it can delete single file when I import the path but I can't  find out all the files that was past 4 days ago and delete it.

let vxlsxfile = 'D:\test2\*.xlsx';
let filedeleted = (DeleteFile('$(vxlsxfile)')=-1);
TRACE File deleted $(filedeleted);

Please help me!!!

Thanks a lot!!

Labels (3)
0 Replies