?
Solved

Delete folder

Posted on 2003-03-13
6
Medium Priority
?
1,244 Views
Last Modified: 2008-03-10
how do i code to delete a folder irregardless of whether it has stuff in it or not ?
0
Comment
Question by:tyfing
[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
6 Comments
 
LVL 6

Expert Comment

by:CyberGhost
ID: 8126352
Maybe there is any API function in Windows that allow this.

But I am not sure. You can however use a for statement to determine if there is something in your directory and then delete one by one file/dir. Only if it is empty Windows will allow you to delete it.

If some1 know othe (better) way, plz let us know...
0
 
LVL 2

Expert Comment

by:j42
ID: 8126617
I assume CyberGhost is right. First you have to delete the content of the folder. You can look up 'FindFirst' in the Delphi help for some help how to get the content of a folder.

Regards
J
0
 
LVL 2

Expert Comment

by:j42
ID: 8126635
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 12

Expert Comment

by:esoftbg
ID: 8127019
0
 
LVL 17

Expert Comment

by:geobul
ID: 8127810
Hi,

Try this:

uses shellapi;

procedure DeleteTree(Dir: String);
var
   T:TSHFileOpStruct;
   X: Integer;
begin
     with T do
     begin
          Wnd:=0;
          wFunc:=FO_DELETE;
          pFrom:=PChar(Dir);
          pTo:=nil;
          { with next line - no recycle bin }
//          fFlags:=FOF_NOCONFIRMATION  ;
     end;
     SHFileOperation(T);
end;

Usage:
DeleteTree('d:\Temp');

Regards, Geo
0
 
LVL 17

Accepted Solution

by:
geobul earned 200 total points
ID: 8127940
Also try this one:

procedure DeleteTree(Dir: string);
var
  Rec: TSearchRec;
begin
  if Dir[Length(Dir)] <> '\' then
    Dir:= Dir + '\';
  if FindFirst(Dir + '*.*', faAnyFile, Rec) = 0 then
  repeat
    if (Rec.Name <> '.') and (Rec.Name <> '..') then
      if Rec.Attr and faDirectory > 0 then
        DeleteTree(Dir + Rec.Name)
      else
       DeleteFile(Dir + Rec.Name);
  until FindNext(Rec) <> 0;
  RemoveDir(ExtractFileDir(Dir));
  FindClose(Rec);
end;

Regards, Geo
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

765 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