[REBOL] Re: For loop and dynamic variable
From: joel:neely:fedex at: 18-Apr-2002 10:52
Hi, Richard,
COFFRE Richard FTO wrote:
> >
> >I want to simplify it like this :
> >
> >for i 1 3 1 [
> > output(i): %output(i).tmp
> > if exists? output(i) [ delete output(i) ]
> >]
> >
>
> for i 1 3 1 [
> if exists? file: join %output reduce [i ".tmp"] [delete file]
> ]
>
Instead of generating the file names, and then testing for their
existence (and status as plain file, not directory), you could
read the current directory and test whether each of its contents
matches the pattern you are looking for:
digits: charset "0123456789"
foreach item read %./ [
if parse/all item [
"output" some digits ".tmp"
][
print [item dir? item]
]
]
This produces output similar to the following:
output1.tmp false
output2.tmp false
output4.tmp false
and, of course, you can do something else with the ones that pass
your criteria.
-jn-