PurgeFiles
The PurgeFiles function deletes files from the file directory specified by AFileMask, where a file date stamp is older the current date by AOlderThanDays number of days.
Setting aIgnoreError to the boolean value of True means that any issues encountered during deleting will simply be ignored - such as if a file cannot be deleted or a directory does not exist. It will just fail silently.
Setting aIgnoreError to the boolean value of False means that any issues encountered during deleting will be thrown back and the delete suspended.
Take extreme care when using this function.
This function permanently deletes the files - they do not just go to the recycle bin.
Declaration: Function PurgeFiles(const AFileMask : string; AOlderThanDays : word; aIgnoreError : boolean) : integer
AOlderThanDays can be a large value to represent files that are years old.
procedure
ScriptEvent (
var
Value : variant);
begin
LogInfo(
''
);
LogInfo(
'Number of Files Deleted : '
+IntToStr(PurgeFiles(
'C:\Test\SampleFiles\*.*'
,
2920
,
False
)));
end
;
In the example above, there are 11 files with the following dates -
12/01/2015
05/02/2024
20/11/2023
05/11/2020
24/10/2023
22/01/2024
12/01/2015
20/05/2021
07/09/2020
21/01/2016
05/02/2024
On the day that the action above was run, only three (3) files were deleted - file number 1, 7, and 10 only.