relpipe-data/examples/guile-file-count-size-sum.sh
author František Kučera <franta-hg@frantovo.cz>
Fri, 25 Sep 2020 14:38:24 +0200
branchv_0
changeset 316 d7ae02390fac
parent 248 e76ca9f7d6cb
permissions -rwxr-xr-x
relpipe-tr-guile.cpp → relpipe-tr-scheme.cpp

#!/bin/bash

# argument: directory path
# prints file count and sum of file sizes

find "$1" -type f -print0 \
	| relpipe-in-filesystem \
		--file path \
		--file size \
	| relpipe-tr-scheme \
		--relation 'f.*' \
		--output-attribute 'count' integer \
		--output-attribute 'sum'   integer \
		--before-records '
			(define $sum   0)
			(define $count 0)
			(define return-sum #f)' \
		--for-each '
			(set! $sum   (+ $sum   $size) )
			(set! $count (+ $count 1    ) )' \
		--where '#f' \
		--after-records '(set! return-sum #t)' \
		--has-more-records '
			(if return-sum
				(begin (set! return-sum #f) #t)
				#f
			)' \
	| relpipe-out-tabular