[REBOL] Re: REBOL Cookbook in Beta
From: nitsch-lists:netcologne at: 29-Aug-2003 16:27
Am Freitag, 29. August 2003 06:57 schrieb Volker Nitsch:
> Am Donnerstag, 28. August 2003 23:25 schrieb [carl--rebol--com]:
>
[snip]
(the "reply" of my mailer trashes the responded message, so i cite myself
by hand)
Volker Nitsch fundamentally clever wrote the largest nop since he programmed:
->>>>>>>>>>
also the example is nice for an article about "how to copy a directory"?
!>>
This code will copy all the text files found in your current directory:
foreach file read %./ [
if find [%.txt %.text] suffix? file [
write/binary file read/binary file
]
]
You can add additional file suffixes if necessary.
(/me added /binary)
<<!
<<<<<<<<<-
Overwrites files with itself..
Erm, well, it could be named "touch"?
but together with the following:
->>>>>>>>>>>>>>>>
Get a Directory File List
:
it may be surprising that
read %other-dir/
returns only the files, without directories.
so
foreach file read %other-dir/[
process-file file
]
fails.
must be
dir: read %other-dir
foreach file dir[
process-file dir/:file
;or join dir file
]
<<<<<<<<<<<<<<<-
it would give a "working with two directories":
src-dir: read %source-dir/
dst-dir: %dest-dir/
foreach file src-dir[
if find [%.txt %.text] suffix? file [
write/binary dst-dir/:file read/binary src-dir/:file
]
]
i often use repeat in a similar way, would call it "working with two series":
texts: ["hi" "ho" "hey"]
colors: [red green blue]
;how to make [ ["hi" red] ["ho" green] ["hey" blue] ]?
;'foreach works only with one series..
out: copy[]
repeat i length? texts[
append/only out reduce[ texts/:i colors/:i]
]
works basically like the directory-stuff:
use an index present in both (file / integer),
access it with a path ( dst-dir/:file / texts/:i ).
is this information somehow usefull?
Should i try an article?
-Volker