file count
[1/3] from: ammon:addept:ws at: 14-Dec-2002 15:26
Hi,
I am attempting to write a function that will count the files and the directoried inside
of a given directory, but somewhere it is killing me in recursion. Here is the function:
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
]
The probe in their shows me that it is only getting one level deep and only goes through
the first three folders then kills. Any ideas?
Thanks!!
Ammon Johnson --- CIO
Addept ------------------ (www.addept.ws)
435-616-2322 -------- (ammon at addept.ws)
[2/3] from: ammon:addept:ws at: 14-Dec-2002 16:58
Hi again!
Dock came along on the REBOL AltME world and saved the day:
file-counter: func [file [file!] /init][
if init [filecnt: folcnt: 0]
foreach f read file [
either dir? append copy file f [
folcnt: folcnt + 1
file-counter probe append copy file f
][
filecnt: filecnt + 1
]
]
print filecnt
print folcnt
]
Ammon Johnson --- CIO
Addept ------------------ (www.addept.ws)
435-616-2322 -------- (ammon at addept.ws)
----- Original Message -----
From: "Ammon Johnson" <[ammon--addept--ws]>
To: <[rebol-list--rebol--com]>
Sent: Saturday, December 14, 2002 3:26 PM
Subject: [REBOL] file count
> Hi,
>
> I am attempting to write a function that will count the files and the
directoried inside of a given directory, but somewhere it is killing me in
recursion. Here is the function:
[3/3] 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]
<<quoted lines omitted: 9>>
> 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 ]
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted