1 unit Unit1; 2 3 interface 4 5 uses 6 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 7 Dialogs, StdCtrls; 8 9 type 10 TForm1 = class(TForm) 11 Button1: TButton; 12 procedure Button1Click(Sender: TObject); 13 private 14 { Private declarations } 15 public 16 { Public declarations } 17 end; 18 19 var 20 Form1: TForm1; 21 22 implementation 23 24 {$R *.dfm} 25 26 procedure DeleteFiles(sMask, sPath: string); 27 var 28 SearchRec: TSearchRec; 29 Found: Integer; 30 begin 31 sPath := IncludeTrailingPathDelimiter(sPath); 32 Found := FindFirst(sPath + sMask, faAnyFile, SearchRec); 33 try 34 while (Found = 0) do 35 begin 36 if not (SearchRec.Attr and faDirectory > 0) then 37 DeleteFile(sPath + SearchRec.Name); 38 Found := FindNext(SearchRec); 39 end; 40 finally 41 FindClose(SearchRec); 42 end; 43 end; 44 45 procedure TForm1.Button1Click(Sender: TObject); 46 begin 47 DeleteFiles('*.txt','C:\test\'); 48 end; 49 50 end.