-- Use RXQUEUE to filter the output from a Windows DIR command
-- Display a list of all files larger than 10000 bytes with their
-- file sizes, and finally print the sum of the sizes of all large files
size_limit = 10000 -- dividing line between large and small
size_total = 0 -- sum of large file sizes
numeric digits 14 -- handle very large file sizes
-- Create a new queue so that this program cannot interfere with data
-- placed on the queue by another program.
queue_name = rxqueue("Create")
call rxqueue "Set", queue_name
-- request DIR output in the date/time/size/name format
-- with no thousands separator in file sizes
"DIR /N /-C | RXQUEUE" queue_name
-- discard five header lines
do 5
pull .
end
-- now all lines are file or directory lines, except for two at the end
do queued() - 2 -- ignore last two lines
parse pull . . size name -- parse file name and file size
-- we ignore "<DIR>" lines and small files
if size <> "<DIR>", size > size_limit then do
say format(size, 14) name
size_total = size_total + size
end
end
say "The total size of files larger than" size_limit "bytes is" size_total
-- we delete our queue, which discards the lines remaining in it
call rxqueue "Delete", queue_name