[REBOL] Re: Recursive-Read question
From: chris:ross-gill at: 6-Nov-2002 9:41
Hi Bryan,
> The format would be
> <folder>
> <file/>
> <file/>
> <folder>
> <file/>
> <file/>
> </folder>
> </folder>
[spaces added]
The function below will create the hierarchy as desired.
Usage:
write %file-list.xml recurse-xml %folder/
I've used a value local to the function 'xml, and I'm not sure if that's the
right approach. The function and xml could also be wrapped in an object -
ctx-xmldir: context [
xml: ""
set 'recurse-xml func [...][...]
]
- Chris
--
REBOL []
use [xml][
recurse-xml: func [
{
Creates an XML string listing all files and sub-directories of
provided folder.
}
dir [file! url!]
"The base-level directory (works for ftp too!)"
/sub "For recursive use, do not set."
/indent ind [string!]
"Indent (used internally)"
/local files [block!]
][
dir: dirize dir
if not indent [ind: copy ""]
if not sub [
xml: copy {<?xml version="1.0" encoding="iso-8859-1"?>}
repend xml [newline build-tag reduce ['files 'path dir]]
]
files: sort read dir
foreach file files [
either dir? join dir file [
repend xml [
newline ind
build-tag reduce [
'folder
'name file
'path dir
'modified modified? join dir file
]
]
recurse-xml/sub/indent join dir file append copy ind " "
repend xml [newline ind </folder>]
][
repend xml [
newline ind
build-tag reduce [
'file
'name file
'path dir
'modified modified? join dir file
'size size? join dir file
to-word "/"
]
]
]
]
if not sub [return repend xml [newline </files>]]
]
]