home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / space2.zip / SPACE.CMD
OS/2 REXX Batch file  |  1994-03-17  |  5KB  |  205 lines

  1. /* Rexx -------------------------------------------------------- *
  2.  * Name:      SPACE.CMD                                          *
  3.  *                                                               *
  4.  * Function:  To add up the disk space used by all files in a    *
  5.  *            given directory.                                   *
  6.  *            Works in both OS/2 1.3 and 2.0. Accepts HPFS       *
  7.  *            directory names.  If /s is specified as a parameter*
  8.  *            this program will recurse into subdiretories.      *
  9.  *                                                               *
  10.  * Syntax:    SPACE <directory> [/s]                             *
  11.  *                                                               *
  12.  * Author:    Jose Xavier                                        *
  13.  *            Compuserve: 71213,1142                             *
  14.  *                                                               *
  15.  * History:                                                      *
  16.  *            Michael A. Higgins (CIS:72137,626)                 *
  17.  *              03/17/94 - Made a few modifications to work in   *
  18.  *              my environment, and hopefully in all.  I use the *
  19.  *              SET DOSCMD environment variable and the /p       *
  20.  *              switch is set, it would not work correctly.      *
  21.  *              Also added the /a switch to the DIR command to   *
  22.  *              get all system and hidden files too.             *
  23.  *                                                               *
  24.  * ------------------------------------------------------------- */
  25.  
  26.  
  27. arg dir rsw
  28.  
  29. /**
  30. *** Override the dircmd environment variable if set.  Will revert
  31. *** back upon exit of the procedure.
  32. ***
  33. *** M. Higgins 03/17/94
  34. **/
  35. if \setlocal() then do
  36.    say 'Error: could save the current environment.'
  37.    exit( - 1 )
  38. end  /* Do */
  39. nRC = value( 'dircmd', '', 'OS2ENVIRONMENT' )
  40.  
  41.  
  42. /* If only subdirectory switch */ 
  43.  
  44. if dir = '/s' | dir = '/S' then do
  45.    rsw = '/S'
  46.    dir = ''
  47. end
  48.  
  49. if dir = '-s' | dir = '-S' then do
  50.    rsw = '/S'
  51.    dir = ''
  52. end
  53.  
  54. if dir = '/?' | dir = '-?' then do
  55.    rsw = '/?'
  56.    dir = ''
  57. end
  58.  
  59. if rsw = '/?' then do
  60.    rc = usage()
  61.    return 0
  62. end
  63.  
  64. /* if no directory name assume current directory */
  65.  
  66. if dir = '' then
  67.    dir = directory()
  68.  
  69. /* Create temporary queue for storing directory names */
  70.  
  71. rc  = RxQueue('Delete','DIRQ')
  72. rc  = RxQueue('Create','DIRQ')
  73. old = RxQueue('Set','DIRQ')
  74.  
  75. say ' '
  76. say '        ******* SPACE USAGE FOR 'dir' ********'
  77. say ' '
  78.  
  79. if substr(dir,length(dir),1) = '\' then
  80.    dir = substr(dir,1,length(dir)-1)
  81.  
  82. size. = 0
  83. name. = ' '
  84. lev = 0
  85. plev = 0
  86. push dir
  87. push lev
  88.  
  89. do while (queued() \=0)
  90.    parse pull lev
  91.    parse pull dirt
  92.    if plev > 1 & lev < plev then do
  93.       ind = plev - 1
  94.       do while ind >= lev
  95.          fomo = conv(size.ind)
  96.          say substr('-------------- 'name.ind,1,60),
  97.          right(fomo,10)
  98.          ind = ind - 1
  99.       end
  100.    end
  101.    if lev \= plev then
  102.       plev = lev
  103.    name.lev = dirt
  104.    dsize   = 0
  105.    difil   = dirt
  106.    /* add up the sizes of all files in directory dirt */
  107.    call add_up
  108.    size.lev = dsize
  109.    fomo = conv(dsize)
  110.    say substr(difil,1,40) right(fomo,10)
  111.    if lev \= 0 then do
  112.       ind = lev - 1
  113.       do while ind >= 0
  114.          size.ind = size.ind + dsize
  115.          ind = ind - 1
  116.       end
  117.    end
  118. end
  119.  
  120. /* remove the temporary file */
  121. '@del c:\dirf 1>nul 2>nul'
  122.  
  123. if lev > 0 then do
  124.    lev = lev - 1
  125.    do while lev >= 0
  126.       fomo = conv(size.lev)
  127.       say substr('-------------- 'name.lev,1,60),
  128.       right(fomo,10)
  129.       lev = lev - 1
  130.    end
  131. end
  132.  
  133. rc  = RxQueue('Set',old)
  134. rc  = RxQueue('Delete','DIRQ')
  135.  
  136. return
  137.  
  138. add_up:
  139. dtemp   = 'c:\dirf'
  140.  
  141. /**
  142. *** Added the /a switch so that all files, system and hidden,
  143. *** get included in the count.
  144. *** M. Higgins  03/17/94
  145. **/
  146.  
  147. '@dir "'dirt'" /a > 'dtemp
  148.  
  149. do while lines(dtemp) > 0
  150.    dline = linein(dtemp)
  151.    push dline
  152.  
  153.    /**
  154.    *** Added upper clause so that following IF statement will
  155.    *** will be evaluated correctly.  Also changed FILE(S) to
  156.    *** be all upper case.
  157.    *** M. Higgins  03/17/94
  158.    **/
  159.    parse upper pull date time size nod file
  160.    if time \= 'FILE(S)' then do
  161.  
  162.       if datatype(size) = 'NUM' then
  163.          dsize   = dsize   + size
  164.  
  165.       else do
  166.          if size = '<DIR>' then
  167.             if rsw = '/S' then do
  168.                file = strip(file)
  169.                if file \= '.' & file \= '..' then do
  170.                   file=dirt'\'file
  171.                   push file
  172.                   push lev+1
  173.                end
  174.             end
  175.       end
  176.    end
  177. end
  178. rc = lineout(dtemp)
  179. '@del 'dtemp
  180. return
  181.  
  182. conv: procedure
  183. arg numb
  184.    len = length(numb)
  185.    lop = len % 3
  186.    do lop
  187.       if (len > lop*3) then do
  188.          numb = insert(',',numb,len-lop*3)
  189.          len   = len + 1
  190.       end
  191.       lop = lop - 1
  192.    end
  193. return(numb)
  194.  
  195. usage: procedure
  196.  
  197. say ' '
  198. say 'SYNTAX: SPACE [directory] [options]'
  199. say ' '
  200. say '        If directory is not passed, current directory will be used.'
  201. say ' '
  202. say 'Options: /s or -s to report space usage of subdirectories'
  203. say '         /? or -? help'
  204. return (0)
  205.