home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / wuz131.zip / Kill-Dir.Cmd < prev    next >
OS/2 REXX Batch file  |  1994-04-17  |  3KB  |  112 lines

  1. /* Remove all files from directory and remove directory */
  2. /* (c) Copyright 1993 Scott Maxwell.            */
  3.  
  4. parse arg Name
  5.  
  6. if (Left(Name,1) = '/') | (Left(Name,1) = '-') then
  7.   parse var Name Options Name
  8. else
  9.   Options = ''
  10.  
  11. Name = Strip(Name,,'"')
  12. Options = Translate(Options)
  13.  
  14. if (Options \= '') & (Options \= '/X') & (Options \= '-X') then signal ShowUsage
  15. if Name = '' then signal ShowUsage
  16.  
  17. dir.1 = Directory()
  18. if SubStr(Name,2,1) = ':' then do
  19.   if (length(Name) = 2) | ((length(Name) = 3) & (Right(Name,1) = '\')) then do
  20.     say "What?! I refuse to delete the root of any drive."
  21.     exit(1)
  22.   end
  23.   if SubStr(Name,3,1) = '.' then do
  24.     say "I refuse to kill relatives! It's too dangerous."
  25.     exit(1)
  26.   end
  27.   dir.2 = Directory(Left(Name,2))
  28.   if dir.2 = '\' then do
  29.     say "No drive" Left(Name,2)
  30.     exit(1)
  31.   end
  32. end
  33. else do
  34.   if Left(Name,1) = '.' then do
  35.     say "I refuse to kill relatives! It's too dangerous."
  36.     exit(1)
  37.   end
  38.   if Name = '\' then do
  39.     say "What?! I refuse to delete the root of any drive."
  40.     exit(1)
  41.   end
  42.   dir.2 = dir.1
  43. end
  44.  
  45. fName = directory(Name)
  46. if fName = '\' then do
  47.   say Name": directory not found"
  48.   exit(1)
  49. end
  50.  
  51. Call Directory dir.2
  52. Call Directory dir.1
  53.  
  54. Name = fName
  55.  
  56.  
  57. CALL RxFuncAdd 'SysRmDir','RexxUtil','SysRmDir'
  58. if Check4OS2()=1 THEN
  59.   '@del /qsxyz "'Name'*" 2> nul'
  60. else do
  61.   CALL RxFuncAdd 'SysFileTree','RexxUtil','SysFileTree'
  62.   CALL RxFuncAdd 'SysFileDelete','RexxUtil','SysFileDelete'
  63.   Call SysFileTree Name'*.*','dir','FS','*****','-*---'
  64.  
  65.   do i=1 to dir.0
  66.     parse VAR dir.i . . . . fname
  67.     Call 'SysFileDelete' STRIP(fname)
  68.   end
  69.  
  70.   Call SysFileTree Name,'dir','SD','*****','-*---'
  71.   do i=1 to dir.0
  72.     parse VAR dir.i . . . . fname
  73.     Call 'SysRmDir' STRIP(fname)
  74.   end
  75.   Call SysRmDir Left(Name,LENGTH(Name)-1)
  76. end
  77.  
  78. if Stream( Name, 'C', 'QUERY EXISTS' ) \= '' then do
  79.   '@attrib -h' Name'zclr.cmd > nul 2> nul'
  80.   '@del' Name'zclr.cmd > nul 2> nul'
  81.   if SysRmDir(Left(Name,LENGTH(Name)-1)) \= 0 then do
  82.     say "Can't remove" Name
  83.     exit
  84.   end
  85. end
  86.  
  87. if Right(Options,1) = 'X' then
  88.    '@exit'
  89. exit(0)
  90.  
  91.  
  92. Check4OS2: procedure
  93.   '@set is4os2=%_4ver'
  94.   return DATATYPE(VALUE(is4os2,,OS2ENVIRONMENT),'N')
  95.  
  96. ShowUsage:
  97.   say "USAGE: Kill-Dir [-x] directory-name"
  98.   say "  Deletes the specified directory and all of its contents"
  99.   say "  If -x option is specified, the OS/2 window is closed"
  100.   exit
  101.  
  102. Directory: procedure
  103.   arg Name
  104.   Name = Strip(Name,,'"')
  105.   if Length(Name) > 3 then
  106.     if Right(Name,1) = '\' then
  107.       Name = Left(Name,LENGTH(Name)-1)
  108.   n = 'DIRECTORY'(Name)
  109.   if Right(n,1) \= '\' then
  110.     n = n'\'
  111. return n
  112.