• Deltree?

    From Eddy Thilleman@2:280/5143.7 to Lee Aroner on Thursday, May 10, 2001 00:52:20
    Hello Lee,

    Tuesday 08 May 2001 13:35, Lee Aroner wrote to Eddy Thilleman:

    With a recursive routine, it's easy. If you want my source, let me
    know.

    I've also made a non-recursive one ages ago, it's in pascal and for DOS (I haven't ported that one).

    Why sure. Always happy to see other folk's ideas on coding.
    Appreciate that sir...

    I use Virtual Pascal/2. I've also compiled it successfully with Speed Pascal v1.5.
    Here is the bare bones version (some lines will be wrapped):

    ------------------- begin of deltree.pas -------------------
    uses DOS;
    {$I-}

    Var
    i : byte;
    keepdir : boolean;
    written : LongInt;
    IORes : LongInt;
    f : file;

    {$S+}
    Procedure DelPath( path: string );
    var
    DR : SearchRec;

    begin
    FindFirst( path + '\*', AnyFile, DR );
    while (DosError = 0) do
    begin
    if (DR.Attr and Directory) = Directory then
    begin
    if ((DR.Name <> '.') and (DR.Name <> '..')) then
    begin
    DelPath( path + '\' + DR.Name );
    RmDir( path + '\' + DR.Name );
    IORes := IOResult;
    if IORes = 0 then
    writeln( path + '\' + DR.Name + ' removed' )
    else
    begin
    writeln( 'Error ', IORes, ' removing ' + path + '\' + DR.Name );
    Halt( IORes );
    end;
    { if dir removed }
    end
    end
    else
    begin
    Assign( f, path + '\' + DR.Name );
    Erase( f );
    IORes := IOResult;
    if IORes = 0 then
    writeln( path + '\' + DR.Name + ' deleted' )
    else
    begin
    writeln( 'Error ', IORes, ' deleting ' + path + '\' + DR.Name );
    Halt( IORes );
    end;
    { if file deleted }
    end;
    {}
    FindNext( DR );
    end;
    end;
    {$S-}


    begin
    keepdir := False;
    for i := 1 to ParamCount do
    begin
    if (paramstr( i ) = '/k') or (paramstr( i ) = '/K') then
    keepdir := True
    else
    begin
    DelPath( paramstr( i ) );
    if not keepdir then
    begin
    RmDir( paramstr( i ) );
    IORes := IOResult;
    if IORes = 0 then
    writeln( paramstr( i ) + ' removed' )
    else
    begin
    writeln( 'Error ', IORes, ' removing ' + paramstr( i ) );
    Halt( IORes );
    end;
    { if dir removed }
    end; { if not keepdir }
    end;
    { parameter /q ? }
    end;
    end.
    -------------------- end of deltree.pas --------------------

    Enjoy! :-)


    Greetings -=Eddy=-

    email: e.thilleman@freeler.nl
    e.thilleman@hccnet.nl

    ... He who laughs last uses OS/2.
    --- GoldED/2 3.0.1
    * Origin: Do still life on your computer -- run WinDOZE. (2:280/5143.7)