REXX Tips & Tricks, Version 2.80


Inf-HTML [About][Toc][Index] 0.9b (c) 1995 Peter Childs


Delete a directory(-tree)





 
/* ------------------------------------------------------------------ */
/* function: Delete all files in a directory and in all its           */
/*           sub directories!                                         */
/*                                                                    */
/* call:     DeleteDirectory dirToDelete                              */
/*                                                                    */
/* where:    dirToDelete - directory to delete                        */
/*                                                                    */
/* returns:  0 - okay                                                 */
/*          -1 - drive not ready                                      */
/*                                                                    */
/* note:     see also The function SysDestroyObject                   */
/*                                                                    */
DeleteDirectory: PROCEDURE
  parse arg dirToDelete

                        /* file or device for messages                */
  prog.__LogAll = "2>NUL 1>NUL"

                        /* init the return code                       */
  thisRC = -1
                        /* check if the drive is ready                */
  SIGNAL ON NOTREADY Name DeleteDirectoryError
  call stream fileSpec( "drive", dirToDelete ) || "\*"

                        /* put a list of all subdirectories in the    */
                        /* queue                                      */
  "@dir /s/f /Ad " dirToDelete "2>NUL | RXQUEUE /lifo "

  do while queued() <> 0
    dirToDel = lineIn( "QUEUE:" )
    if dirTodel <> "" & right( dirToDel,2 ) <> "\." & ,
       right( dirToDel,3 )  <> "\.." then
    do
                    /* also delete hidden, system and read-only files */
      "@attrib -r -s -h " dirToDel || "\*.*" prog.__LogAll

/*    "@(echo Y & echo J ) | del " dirToDel || "\*.*" prog.__LogAll   */

      "@del /n " dirToDel || "\*.*" prog.__LogAll            /* v2.60 */

      if dirToDel <> dirToDelete then
        "@rd  " dirToDel prog.__LogAll
    end /* if dirToDel <> "" then */
  end /* do while queued <> 0 */

                    /* also delete hidden, system and read-only files */
  "@attrib -r -s -h " dirToDelete || "\*.*" prog.__LogAll

/*"@(echo Y & echo J) | del " dirToDelete || "\*.*" prog.__LogAll     */

  "@del /n " dirToDelete || "\*.*" prog.__LogAll             /* v2.60 */

  "@rd " dirToDelete prog.__logAll

  thisRC = 0

DeleteDirectoryError:

RETURN thisRC


  

Inf-HTML End Run - Successful