Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

D1:Recursiv deletion of directories and content

Posted on 1997-12-10
4
Medium Priority
?
224 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
  • 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 200 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

972 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