Re: Re: count files in DelphiPosted by Joey *DClub* on July 23, 2004 at 01:17:08: In Reply to: count files in Delphi posted by rachael on July 22, 2004 at 21:51:51: Here is the code in the form of a procedure. This will work if you add it to your code and your form is called Form1. If not just change the bottom line :P procedure CountAndDeleteFiles(FilePath: string); var SearchRec: TSearchRec; BeforeCount, AfterCount: Integer; begin BeforeCount := 0; AfterCount := 0; if FilePath[Length(FilePath)] '\' then FilePath := FilePath + '\'; if FindFirst(FilePath + '*.*', faAnyFile and not faDirectory, SearchRec) = 0 then begin Inc(BeforeCount); DeleteFile(FilePath + SearchRec.Name); while FindNext(SearchRec) = 0 do begin Inc(BeforeCount); DeleteFile(FilePath + SearchRec.Name); end; end; if FindFirst(FilePath + '*.*', faAnyFile and not faDirectory, SearchRec) = 0 then begin Inc(AfterCount); DeleteFile(FilePath + SearchRec.Name); while FindNext(SearchRec) = 0 do begin Inc(AfterCount); DeleteFile(FilePath + SearchRec.Name); end; end; FindClose(SearchRec); Form1.Label1.Caption := IntToStr(BeforeCount) + '/' + IntToStr(AfterCount); end; Joey ^__^ if its not what ya wanted just post back :P Related Articles and Replies
|