Link to home
Start Free TrialLog in
Avatar of p05010
p05010

asked on

How to delete a bunch of files with wildcards ?

How to delete a bunch of files with wildcards ?
How to delete the directory that contains those file ?
Can I do it with the DeleteFile() function ?

p05010
ASKER CERTIFIED SOLUTION
Avatar of Brian Mulder
Brian Mulder
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Stupid me.............

Ok a bit sleepy but here is the trick that will do it

procedure TForm1.Button1Click(Sender: TObject);
var
  sr : TSearchRec;
  res: integer;
  thisdir: string;
begin
  thisdir :='c:\arj\dtext23\bitmaps';
  if DirectoryExists(thisdir) then
  try
    SetCurrentDir(Thisdir);
    res := FindFirst('*.*', 0, sr);
    try
      while (res = 0) do
      begin
        if (sr.name <> '.') and (sr.name <> '..') then
        begin
          DeleteFile(sr.name);
        end;
        res := FindNext(sr);
      end;
    finally
      FindClose(sr);
    end;
    SetCurrentDir('c:\arj\dtext23');
    RmDir(ThisDir);
  except on E:Exception do
      showmessage(E.Message);
  end;
end;

put Filectrl in your uses clause for the directoryexists function.

Avatar of p05010
p05010

ASKER

Thx, I will try it.
Looks good a first sight.