home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rexxalgo.zip / TESTALGO / ErasPath.CMD < prev    next >
OS/2 REXX Batch file  |  1997-08-25  |  5KB  |  130 lines

  1. /* REXX **********************************************/
  2. /* Frame for your Rexx program. Verify please!       */
  3. /* Program name: ErasPath.CMD                        */
  4. /* Function    : Delete directory Path               */
  5. /* Syntax      : ErasPath _erasePath                 */
  6. /* Changes     : No                                  */
  7. /*                                                   */
  8. /* Made use of GREED.  28 Dec 1996 / 00:39:39   JRK  */
  9. /*****************************************************/
  10. /* (C) Copyright Janosch R. Kowalczyk, 1996.         */
  11. /* All rights reserved.                              */
  12. /*****************************************************/
  13. Parse Source . calledAs .
  14. If calledAs \= "COMMAND" Then 
  15.   Parse Arg _erasePath .
  16. Else 
  17.   Parse Arg _erasePath, .
  18.  
  19. /*===============(Exception handling)================*/
  20. Signal On Failure  Name CLEARUP
  21. Signal On Halt     Name CLEARUP
  22. Signal On Syntax   Name CLEARUP
  23. Signal On NotReady Name CLEARUP
  24.  
  25. /*===========(Initialize RexxUtil support)===========*/
  26. If RxFuncQuery('SysLoadFuncs') Then Do
  27.   Call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  28.   Call SysLoadFuncs
  29. End /* If RxFuncQuery... */
  30.  
  31. Say 
  32. Say Center( "( DELETE DIRECTORY PATH )", 80, '*')
  33.  
  34. If _erasePath = '' Then 
  35.   _erasePath = 'C:\TEST\MAKE\PATH\PROCEDUR\RECURSIV\NEW\TEST'
  36.  
  37. Call MakePath _erasePath 
  38. Say
  39. Call ErasePath _erasePath 
  40.  
  41. Say
  42. Call LineOut , "Press any key to exit "
  43. Call LineIn
  44.  
  45. /*================(End this program)================*/
  46. Exit
  47.  
  48. CLEARUP:
  49.   Say
  50.   Say 'GREED001E - Break, Failure or Syntax Error'
  51. Exit
  52.  
  53.  
  54.  
  55. /*==============( Delete Directory Path )=============*/
  56. /*                                                 17 */
  57. /* Name.......: ErasePath                             */
  58. /*                                                    */
  59. /* Function...: delete directory path                 */
  60. /*                                                    */
  61. /* Call parm..: _erasePath - directory path to be     */
  62. /*              deleted                               */
  63. /*                                                    */
  64. /* Returns....: formated string                       */
  65. /*                                                    */
  66. /* Syntax.....:                                       */
  67. /*    _erasePath = MakePath( _erasePath )             */
  68. /*                                                    */
  69. /* Changes....: No                                    */
  70. /*                                                    */
  71. /* Author.....: Janosch R. Kowalczyk                  */
  72. /*====================================================*/
  73. ErasePath: Procedure
  74. Arg _erasePath 
  75.  
  76. _erasePath = Strip( _erasePath, , '\' )
  77.  
  78. Do Until Pos('\', _erasePath) = 0 
  79.   rc = SysRmDir( _erasePath )
  80.   If rc > 0 Then
  81.     Say 'Directory:' _erasePath 'not deleted. RC=' rc 
  82.   Else 
  83.     Say _erasePath 'successful deleted'
  84.   _erasePath = SubStr( _erasePath, 1, LastPos('\', _erasePath) - 1)
  85. End
  86.  
  87. Return _erasePath
  88.  
  89.  
  90.  
  91.  
  92. /*=============( Recursive Path Creating )============*/
  93. /*                                                 16 */
  94. /* Name.......: MakePath                              */
  95. /*                                                    */
  96. /* Function...: Create recursive directory path       */
  97. /*                                                    */
  98. /* Call parm..: _destPath  - directory path           */
  99. /*                                                    */
  100. /* Returns....: formated string                       */
  101. /*                                                    */
  102. /* Syntax.....:                                       */
  103. /*    _destPath = MakePath( _destPath )               */
  104. /*                                                    */
  105. /* Changes....: No                                    */
  106. /*                                                    */
  107. /* (C) Copyright Janosch R. Kowalczyk, 1996.          */
  108. /* All rights reserved.                               */
  109. /*====================================================*/
  110. /*---------------(Create Directory Path)--------------*/
  111. MakePath: Procedure
  112. Arg _destPath
  113.  
  114. _destPath = Strip(_destPath,,'\')
  115. If Pos('\', _destPath) = 0 Then Return _destPath
  116.  
  117. /*--------------( Check Directory Path )--------------*/
  118. rc = SysFileTree( _destPath, fileList, 'DO' )
  119. If fileList.0 = 0 Then Do
  120.   /*------------(Directory path not exists)-----------*/
  121.   Call MakePath SubStr(_destPath, 1, LastPos('\', _destPath))  
  122.   rc = SysMkDir( _destPath )
  123.   If rc > 0 & rc \= 5 Then
  124.     Say 'Destination directory:' _destPath 'not created. RC=' rc 
  125.   Else 
  126.     Say _destPath 'successful created'
  127. End
  128.  
  129. Return _destPath
  130.