home *** CD-ROM | disk | FTP | other *** search
/ Amiga Computing 63 / ac063.adf / cinemorphjr.lha / SupportFiles / treesize.rexx < prev    next >
OS/2 REXX Batch file  |  1993-06-08  |  2KB  |  59 lines

  1. /*       ***   treesize.rexx    ***         *
  2.  *  A program to find the size of all the   *
  3.  *  subdirectories of a directory tree      *
  4.  *  recursively;  May be adapted to perform *
  5.  *  various operations on the tree.         */
  6.  
  7. ARG dirname opts .
  8. IF dirname = '' THEN dirname = Pragma('DIR')
  9. IF ~Exists(dirname) THEN DO
  10.    SAY "ERROR in treesize.rexx",
  11.        "- Directory does not exist"
  12.        EXIT 10
  13.    END
  14. s = Treesize(dirname,'',opts)
  15. IF opts = 'QUIET'
  16. THEN SAY 'Total size of files in tree' dirname '=' s
  17. EXIT 0
  18.  
  19. /* Procedure that searches the tree recursively;
  20.    takes the current directory level, a "tab",
  21.    and a printing flag as arguments  */
  22. Treesize:  PROCEDURE
  23.    PARSE ARG level, tab, qu
  24.    IF qu ~= 'QUIET' THEN SAY tab Basename(level)
  25.    IF Right(level,1) ~= ':' THEN level = level || '/'
  26.    subdirs = Showdir(level,'DIR')
  27.    tot = 0
  28.    DO FOREVER WHILE subdirs ~= ''
  29.        PARSE VAR subdirs newdir subdirs
  30.        newdir =  level || newdir
  31.  /* =- At this point we go to next level    */
  32.        size = Treesize(newdir,tab '   ',qu)
  33.  /* =- Procedure returns to this point      */
  34.        tot = size + tot
  35.        END
  36.    size = file_total(level)
  37.    tot = tot + size
  38.    level = Basename(level)
  39.    IF size ~= 0 THEN IF qu ~= 'QUIET'
  40.       THEN SAY tab 'Size of files in' level 'is' size
  41.    IF qu ~= 'QUIET'
  42.    THEN SAY tab 'Total size of files in' level 'is' tot
  43.    RETURN tot
  44.  
  45. /* Basename(level) - get and  highlight the level     name from a full filespec */
  46. Basename: PROCEDURE
  47.    fullname = strip(Arg(1),'T','/')
  48.    slash = lastpos('/',fullname)
  49.    IF slash = 0
  50.    THEN DO
  51.       PARSE VAR fullname dev':'dir
  52.       IF dir = '' THEN base = fullname
  53.       ELSE base = dir
  54.       END
  55.    ELSE  PARSE VAR fullname +slash base
  56.    RETURN '9b'x||'33m'||base||'9b'x||'0m'
  57. <D>
  58.  
  59.