Solved

D1:Recursiv deletion of directories and content

Posted on 1997-12-10
4
221 Views
Last Modified: 2010-04-04
How can I delete a directory with contents, including subdirectories in Delphi 1.0 (Windows 3.11) ?
0
Comment
Question by:zaibatzuka
[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
4 Comments
 
LVL 8

Expert Comment

by:ZifNab
ID: 1353287
Let me propose this :
 1. Look for a component which does recursif searching.
     (enough freeware components on the net)
 2. Delete every founded file or directory

Here is already a code for searchin the entire disk. Easely changed in searching through one directory.

unit Audit1;
interface
uses windos;

var
  dest:string;

procedure dorecurse(dir:string);

implementation
{$R *.DFM}
Procedure Process (dir:string; Searchrec:tsearchrec);
begin
   showmessage (Searchrec.name);
   case Searchrec.attr of
   $10:
      if (searchrec.name<>'.') and (searchrec.name<>'..') then
          begin
        dorecurse (dir+'\'+searchrec.name);
                writeln (dir);
          end;
   end;
end;

Procedure Dorecurse(dir:string);
var
   Searchrec:Tsearchrec;
   pc: array[0..79] of Char;
   
begin
   StrPCopy(pc, dir+'\*.*');
   FindFirst(pc, FaAnyfile, SearchRec);
   Process (dir,SearchRec);
   while FindNext(SearchRec)<>-18 do
   begin
      Process (dir,SearchRec);
   end;
end;

Procedure startsearch;
begin
   dorecurse (paramstr(1));
end;

begin
   startsearch;
end.

Have fun,
c.u. ZifNab;
0
 
LVL 1

Accepted Solution

by:
aluiken earned 100 total points
ID: 1353288
Hi there,

You should use findfirst and the findnext functions
then delete / process every file

You will need a procedure like this:

procedure DelTree(const RootDir  : String);
var
  SearchRec : TSearchRec;
begin
Try
    ChDir(RootDir);  {Path to the directory  given as parameter }
    FindFirst('*.*',faAnyFile,SearchRec);
    Erc := 0;
    while Erc = 0 do  begin
        if      ((SearchRec.Name <> '.' )
        and  (SearchRec.Name <> '..')) then begin
              if  (SearchRec.Attr and faDirectory>0) then begin
                    { Have found a directory, not a file.
                       Recusively call ouselves to delete its files }
                     DelTree(SearchRec.Name);
                     end
              else begin
                    {Found a file.  Delete it or whatever
                     you want to do here }
                     end;
         end;
          Erc := FindNext (SearchRec);
            otherwise Erc = negative DOS error }
            Application.ProcessMessages;
    end;
finally
      if Length(RootDir) > 3 then ChDir('..');
end;
end;

So thats it.

Regards, Arijan
0
 

Author Comment

by:zaibatzuka
ID: 1353289
OK. Note that the line above Application.ProcessMessages is missing a left braces. Indentations would have made it easier to follow the code.
Thanks.
0
 
LVL 1

Expert Comment

by:aluiken
ID: 1353290
hey a html memo is sumthing else then the borland delphi UI
=)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

710 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