Delete all files within directory

Posted in Files & folders

Use FileListBox component. Specify a necessary directory to this component and remove files by using DeleteFile procedure.

procedure TForm1.Button1Click(Sender: TObject);
var
  i: Integer;
begin
  for i:=0 to FileListBox1.Items.Count-1 do
    DeleteFile(FileListBox1.Items[i]);
  FileListBox1.Update;
end;