Solved

How to delete a bunch of files with wildcards ?

Posted on 1999-01-11
3
441 Views
Last Modified: 2010-04-04
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
0
Comment
Question by:p05010
  • 2
3 Comments
 
LVL 44

Accepted Solution

by:
bruintje earned 0 total points
ID: 1355915
Hi p05010,

You can indeed delete your files with the DeleteFile function and then remove the empty directory with rmDir (with the precursion that the directory is empty)

:O)
Hope this helps
brUINTje.
0
 
LVL 44

Expert Comment

by:bruintje
ID: 1355916
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.

0
 
LVL 1

Author Comment

by:p05010
ID: 1355917
Thx, I will try it.
Looks good a first sight.
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question