TIP: Click on subject to list as thread! ANSI
echo: z3_pascal
to: Bob Lawrence
from: Doug Brendish
date: 1996-03-09 15:51:14
subject: Making directories

This is how I would probably do it. Well there may be better ways, but this
would probably be fairly thorough in getting rid of the files and any sub
dirs in the work dir too. I have not tested it!! I only just wrote it up
just then as an example, so there may be errors. I also don't have
Delphi(Not till they make it for OS/2) so this is DOS. I don't know how
much difference there is. It should give an idea though.
Uses DOS;

Procedure Prune(P); {Recursive file + dir delete}
Var Path:string;
    SR:Searchrec;
    F:File;
Begin
 FindFirst(P+'*.*',AnyFile,SR);
 While DosError = 0 do
 Begin
  If (SR.Name[1]  '.') then
  Begin
   If SR.Attr = $10 then
   Begin
    ChDir(SR.Name);
    Del_Work;
    GetDir(0,Path);
    CHDir('..');
    {$I-} RMDir(Path);{$I+}
    Err:=IOResult;
   End else
   Begin
    GetDir(0,Path);
    Assign(F,SR.Name);
    SetFAttr(F,$20);
    {$I-}Erase(F);{I+}
    Err:=IOResult;
   End;
  End;
  FindNext(SR);
 End;
End;

Procedure Del_Work(P);
Begin
 Prune(P);    {Call recursive delete to kill all files and sub dirs of work}
 CHDir('..');
 Delete(P,length(P),1); {remove trailing \}
 {$I-} RMDir(P);{$I+}   {Finally delete the work dir its self}
End;

Procedure Make_Work;
Var
  Path:string;
Begin
 getpath(0,Path);   {Get current path}
 {$i-} CHDir(path+'\Work');{$I+} {Change to work to see if it exists}
 If IOResult  0 then    {If it don't exist then}
 begin
  {$I-}MKDir(Path+'\Work');{$I+}  {Make it}
 end else
 begin
  Del_Work(Path+'\work\');              {else delete it}
  {$I-} MKDir(Path+'\Work');{$I+}   {Then make it again}
 end;

Begin
 Make_Work; {Make a work directory}
 Do_Stuff; {Do all you work}
 Del_Work('what ever it is');
end.

Hope it helps,
Doug

--- Msgedsq/2 3.10
* Origin: Tir na nOc 066 245944 -=Cead mile failte=- (3:626/667)
SEEN-BY: 633/267 270
@PATH: 626/667 660 711/401 808 50/99 635/544 727 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.