Solved

D1:Recursiv deletion of directories and content

Posted on 1997-12-10
4
222 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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses
Course of the Month7 days, left to enroll

623 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