Hi Mike,

Here's a snippet that almost does the trick: it recurses through subdirectories of a starting directory and returns all files found in a tStringList. Use DeleteFile (dir + sr.name) to delete a file, use FileNameToDateTime(sr.time) to get the date of the file. HTH.

procedure GetFilesInDirectory (const dir: string; list: tStringList);
var
   sr:       tSearchRec;
   ret:      integer;
begin
   list.add (dir);
   ret := findFirst (dir + '*.*', faAnyFile, sr);
   while ret = 0 do begin
      if (sr.name = '.') or (sr.name = '..') then
         // do nothing, special directories
      else if (sr.attr and faDirectory) <> 0 then
GetFilesInDirectory (IncludeTrailingPathDelimiter(dir + sr.name), list)
      else if (sr.Attr and (faSysFile or faVolumeID or faSymLink)) = 0 then
         list.add (dir + sr.name);
      ret := findNext (sr);
   end;
   sysUtils.findClose (sr);
end;


At 09:49 AM 7/24/2012, SoftTech wrote:
Greetings All,

Given a starting directory, does anyone have any code snippet that would recurse thru a starting directory and all sub-directories and delete any file found that is older than a given date.

Any code snippet or tip appreciated.

Thanks,
Mike
__________________________________________________
Delphi-Talk mailing list -> Delphi-Talk@elists.org
http://lists.elists.org/cgi-bin/mailman/listinfo/delphi-talk

__________________________________________________
Delphi-Talk mailing list -> Delphi-Talk@elists.org
http://lists.elists.org/cgi-bin/mailman/listinfo/delphi-talk

Reply via email to