Copy all Files in a Directory
Author: Carl Sassenrath This example requires REBOL/View Return to REBOL Cookbook
Here's how to copy files from one directory to another.
The destination directory will be created if it does not already
exist:
source: %pages/
dest: %archive/
if not exists? dest [make-dir/deep dest]
foreach file read source [
print file
write/binary dest/:file read/binary source/:file
]
|
Note that the source and dest must be directories (and include
the ending slash).
To extend this function to copy files recursively in all
sub-directories, it will need to be made into a function:
copy-dir: func [source dest] [
if not exists? dest [make-dir/deep dest]
foreach file read source [
either find file "/" [
copy-dir source/:file dest/:file
][
print file
write/binary dest/:file read/binary source/:file
]
]
]
|
Now you can write:
copy-dir %pages/ %archive/
|
|