relpipe-data/examples/guile-file-count-size-sum.sh
author František Kučera <franta-hg@frantovo.cz>
Sat, 26 Oct 2019 20:57:42 +0200
branchv_0
changeset 276 cfaf1fa94154
parent 248 e76ca9f7d6cb
child 316 d7ae02390fac
permissions -rwxr-xr-x
rename --keep-file to --file-keep

#!/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-guile \
		--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