Here's an approach that doesn't require the server to have X command enabled. This could be done in one step, but I'm a fan of using generic macros so I'll do that to get my directory listing first. Two choices for doing this: * Filelist macro (Don Henderson) * mp_dirlist macro (yours truly) Now we have a list of filepaths, we can use the `finfo` function to find the last modified date, convert it to a datetime (using a trusty anydtdtme informat), compare the age, and delete as appropriate! data _null_;
set work.mp_dirlist;
drop rc fid close;
format modified_dttm datetime19.;
rc=filename("fref",filepath);
fid=fopen("fref");
if fid>0 then do;
modified=finfo(fid,"Last Modified");
modified_dttm=input(modified,anydtdtm24.);
end;
close=fclose(fid); /* 60secs * 60 mins * 24 hours * 5 days */
if modified_dttm>0 and datetime()-modified_dttm > (60*60*24*5) /* and ext='???'*/ then do;
putlog 'deleting' filename;
rc=fdelete("fref");
end;
run;
... View more