[REBOL] Re: file count
From: joel::neely::fedex::com at: 14-Dec-2002 20:31
Hi, Ammon,
Since I'm on a recursion-and-objects obsession lately, I'd tend to
come up with something like one of these approaches:
1) Explicitly returning a 2-element block of results:
fdc: func [fd [file!] /local nfiles ndirs sd] [
nfiles: ndirs: 0
foreach f read fd [
either dir? sd: join fd f [
sd: fdc sd
nfiles: nfiles + first sd
ndirs: ndirs + 1 + second sd
][
nfiles: nfiles + 1
]
]
reduce [nfiles ndirs]
]
or,
2) Managing the shared accumulators within an object:
odc: make object! [
nfiles: ndirs: 0
_count: func [fd [file!] /local sd] [
foreach f read fd [
either dir? sd: join fd f [
sd: _count sd
ndirs: ndirs + 1
][
nfiles: nfiles + 1
]
][
]
]
count: func [fd [file!]] [
nfiles: ndirs: 0
_count fd
reduce [nfiles ndirs]
]
]
but, of course, YMMV!! ;-)
-jn-
Ammon Johnson wrote:
> file-counter: func [file [file!] /init][
> if init [filecnt: folcnt: 0]
> foreach f read file copy/deep[
> either dir? f [
> folcnt: folcnt + 1
> file-counter probe append copy file f
> ][
> filecnt: filecnt + 1
> ]
> ]
> print filecnt
> print folcnt
> ]
>
--
; Joel Neely joeldotneelyatfedexdotcom
REBOL [] do [ do func [s] [ foreach [a b] s [prin b] ] sort/skip
do function [s] [t] [ t: "" foreach [a b] s [repend t [b a]] t ] {
| e s m!zauafBpcvekexEohthjJakwLrngohOqrlryRnsctdtiub} 2 ]