Hi, Tom...

[EMAIL PROTECTED] wrote:
> 
...
> 
> site: ftp://ftp.rebol.com/pub/downloads/
> pattern: "*.gz"
> files: read site
> foreach file files [
>     if find/match/any file pattern [
>             write/binary file read/binary site/:file
>         ]
>     ]
> 
> what I can't seem to do is have this fetch "*.gz" files, but not
> "gz.bak" files.
>

The gotcha here is that find/match/any will accept any match of
the pattern, regardless of position.  Take a look at this excerpt
from my box (some names changed/deleted for security):

    >> foreach filename sort read %./ [
    [    if find/match/any filename "*.gz" [print filename]
    [    ]
    analog3_32_tar.gz
    blort.gz.bak
    enterprise-4.2-export-us.hppa1.1-hp-hpux10.10.tar.gz
    foo.gz.bak
    labrea.gz.tar
    == none

Since the pattern "*.gz" can match anywhere the sequence ".gz"
appears in the file name (even internally), I get lots of false hits.
To force it to appear only at the end, I can specify a parse rule
that only matches in that case:

    >> foreach filename sort read %./ [
    [    if parse/all filename [thru ".gz"] [print filename]
    [    ]
    analog3_32_tar.gz
    enterprise-3.6-export-us.hppa1.1-hp-hpux10.10.tar.gz
    == none

This is based on the fact that  parse/all string rule  returns
true only if we get all the way to the end of the string, therefore
the ".gz" must occur in the string and must be at the end.

Hope this helps!

-jn-

Reply via email to