How do I Delete Files with a specific extention using Delphi 5

I want to delete all files in a directory that contain the file extention .bin but im not sure how to do this
FreedayAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dougaugCommented:
Try this:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses ShellApi;

function DeleteFiles(Hwnd: THandle; const Files: string): Boolean;
var
  SHFileOperationStruct: TSHFileOpStruct;
begin
  FillChar(SHFileOperationStruct, SizeOf(TSHFileOpStruct), 0);
  with SHFileOperationStruct do
  begin
    Wnd := Hwnd;
    wFunc := FO_DELETE;
    pFrom := PChar(Files);
    fFlags := FOF_SILENT or FOF_NOCONFIRMATION;
  end;
  Result := SHFileOperation(SHFileOperationStruct) = 0;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  DeleteFiles(Handle, 'c:\temp\*.bin');
end;

end.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
FreedayAuthor Commented:
Hi, thanks for the response, this is working, but I had to change the line to, in order for it to delete files from 2 directories

pFrom := PChar(Files+#0+#0);
0
FreedayAuthor Commented:
Thanks!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.