home *** CD-ROM | disk | FTP | other *** search
- /*============================================================================*
- * REXX command: qsize - Query total size of a group of files
- *
- * This command uses the 'ls -lf' command to produce a list of files that
- * match the file specifications. The sizes of the files are added and
- * displayed.
- *
- * This won't give an indication of actual disk usage, since disk allocation
- * strategies are not taken into account by the file size.
- *
- * This command is an example of storing the standard output of a program
- * directly into a REXX private queue. This represents a vast improvement
- * over the method of storing output in a temporary file and then reading
- * the temporary file.
- *
- * 05/22/91 - Created for OS/2.
- * 05/22/91 - Initial version.
- *============================================================================*/
- "@echo off"
-
- /*----------------------------------------------------------------------------*
- * Store arguments in arglist
- *----------------------------------------------------------------------------*/
-
- parse arg arglist
- if arglist == '' then
- do
- say "Usage: qsize fspec ..."
- return(2)
- end
-
- /*----------------------------------------------------------------------------*
- * Create a private queue. Be sure it has nothing in it.
- *----------------------------------------------------------------------------*/
-
- rc=rxqueue("delete", pq)
- qname=rxqueue("create", pq)
- oldq=rxqueue("set", qname)
-
- /*----------------------------------------------------------------------------*
- * Run the ls command and pipe its output into the private queue 'pq'.
- * The 'long' output format of ls is used so we can get each file's size.
- *----------------------------------------------------------------------------*/
-
- cmd = "ls -lf" arglist "| rxqueue pq /fifo"
- cmd
-
- say "File specification(s):" arglist
- say "No. of matching files:" queued()
-
- if queued() = 0 then /* Be sure ls wrote at least one */
- do /* line to stdout */
- say "--- No matching files found."
- return(2)
- end
-
- total = 0 /* Initialize total size */
-
- /*----------------------------------------------------------------------------*
- * Read and process each line of the queue
- *----------------------------------------------------------------------------*/
-
- do while (queued() > 0)
- /*----------------------------------------------------------*
- * Get the next line from the queue, and store entire
- * line in the 'stdline' variable
- *----------------------------------------------------------*/
- parse pull stdline
-
- /*----------------------------------------------------------*
- * Parse the line into its pieces, and add the size to total
- *----------------------------------------------------------*/
- parse value stdline with fmode fsize fdate ftime fname .
- total = total + fsize
- end
-
- say "Total bytes in files: " total
- return(0)
-