home *** CD-ROM | disk | FTP | other *** search
/ The Developer Connection…ice Driver Kit for OS/2 3 / DEV3-D1.ISO / prodtool / util2 / qsize.cmd < prev    next >
Encoding:
Text File  |  1991-09-09  |  3.0 KB  |  79 lines

  1. /*============================================================================*
  2.  * REXX command: qsize - Query total size of a group of files
  3.  *
  4.  * This command uses the 'ls -lf' command to produce a list of files that
  5.  * match the file specifications.  The sizes of the files are added and
  6.  * displayed.
  7.  *
  8.  * This won't give an indication of actual disk usage, since disk allocation
  9.  * strategies are not taken into account by the file size.
  10.  *
  11.  * This command is an example of storing the standard output of a program
  12.  * directly into a REXX private queue.  This represents a vast improvement
  13.  * over the method of storing output in a temporary file and then reading
  14.  * the temporary file.
  15.  *
  16.  * 05/22/91 - Created for OS/2.
  17.  * 05/22/91 - Initial version.
  18.  *============================================================================*/
  19.  "@echo off"
  20.  
  21. /*----------------------------------------------------------------------------*
  22.  * Store arguments in arglist
  23.  *----------------------------------------------------------------------------*/
  24.  
  25.  parse arg arglist
  26.  if arglist == '' then
  27.  do
  28.     say "Usage: qsize fspec ..."
  29.     return(2)
  30.  end
  31.  
  32. /*----------------------------------------------------------------------------*
  33.  * Create a private queue.  Be sure it has nothing in it.
  34.  *----------------------------------------------------------------------------*/
  35.  
  36.  rc=rxqueue("delete", pq)
  37.  qname=rxqueue("create", pq)
  38.  oldq=rxqueue("set", qname)
  39.  
  40. /*----------------------------------------------------------------------------*
  41.  * Run the ls command and pipe its output into the private queue 'pq'.
  42.  * The 'long' output format of ls is used so we can get each file's size.
  43.  *----------------------------------------------------------------------------*/
  44.  
  45.  cmd = "ls -lf" arglist "| rxqueue pq /fifo"
  46.  cmd
  47.  
  48.  say "File specification(s):" arglist
  49.  say "No. of matching files:" queued()
  50.  
  51.  if queued() = 0 then               /* Be sure ls wrote at least one */
  52.  do                                 /* line to stdout */
  53.     say "--- No matching files found."
  54.     return(2)
  55.  end
  56.  
  57.  total = 0                          /* Initialize total size */
  58.  
  59. /*----------------------------------------------------------------------------*
  60.  * Read and process each line of the queue
  61.  *----------------------------------------------------------------------------*/
  62.  
  63.  do while (queued() > 0)
  64.    /*----------------------------------------------------------*
  65.     * Get the next line from the queue, and store entire
  66.     * line in the 'stdline' variable
  67.     *----------------------------------------------------------*/
  68.     parse pull stdline
  69.  
  70.    /*----------------------------------------------------------*
  71.     * Parse the line into its pieces, and add the size to total
  72.     *----------------------------------------------------------*/
  73.     parse value stdline with fmode fsize fdate ftime fname .
  74.     total = total + fsize
  75.  end
  76.  
  77.  say "Total bytes in files: " total
  78.  return(0)
  79.