Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to delete a bunch of files with wildcards ?

Posted on 1999-01-11
3
Medium Priority
?
447 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

618 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