1 2 //--------------------------------------------------------------------------- 3 4 #include <vcl.h> 5 #pragma hdrstop 6 7 #include "Unit1.h" 8 //--------------------------------------------------------------------------- 9 #pragma package(smart_init) 10 #pragma resource "*.dfm" 11 TForm1 *Form1; 12 //--------------------------------------------------------------------------- 13 __fastcall TForm1::TForm1(TComponent* Owner) 14 : TForm(Owner) 15 { 16 } 17 //--------------------------------------------------------------------------- 18 void DeleteFiles(AnsiString sMask, AnsiString sPath){ 19 TSearchRec SearchRec; 20 int iFound; 21 22 sPath = IncludeTrailingPathDelimiter(sPath); 23 iFound = FindFirst(sPath + sMask, faAnyFile, SearchRec); 24 while (iFound == 0){ 25 if ((SearchRec.Attr && faDirectory > 0)== true) { 26 DeleteFile(sPath + SearchRec.Name); 27 } 28 iFound = FindNext(SearchRec); 29 30 } 31 FindClose(SearchRec); 32 33 } 34 35 void __fastcall TForm1::Button1Click(TObject *Sender) 36 { 37 DeleteFiles("*.txt" , "c:\\test"); 38 39 } 40 //---------------------------------------------------------------------------