[REBOL] Re: Matching RE's - pattern matching
From: d4marcus:dtek:chalmers:se at: 23-Mar-2001 19:41
On Fri, 23 Mar 2001, Anton wrote:
> This is what I use in my 'ls function found here:
> http://users.bigpond.net.au/datababies/anton/rebol/dir-utils.r
I downloaded that one a while ago together with shell.r (which someone
else posted). Seems I forgot to check your script for an 'ls function.
But still, what I get with your script is this (as I'm using Linux you
might understand why it is a problem):
>> ls *.R
user.r
But still, I guess I should have a more thorough look, because in one of
my own recent scripts I tried to add some of that functionality. Have a
look if you want:
rebol []
; for example: recurse %. '*/* creates a block structure which can be
; parsed by another script of mine
recurse: func [dir [file!] pattern [any-type!]] [
pattern: either value? 'pattern [
if block? :pattern [pattern: form pattern]
if string? :pattern [replace/all :pattern "/" " "]
to-block :pattern] [[*]]
recurse! (clean-path dirize dir) pattern
]
; compatible to Unix ls -d
recurse!: function [dirpath [file!] pattern [block!]] [
result block dirnext
] [
result: copy []
foreach file sort/case read dirpath [
if match-file file first pattern [
either empty? next pattern [append result file] [
dirnext: to-file reduce [dirpath file]
if dir? dirnext [
block: recurse! dirnext next pattern
if not empty? block [
append result file
append/only result block]]]]
]
result
]
match-file: function [file [file! string!]
pattern [any-word! string!]] [match] [
all [match: find/case/any/match to-string file pattern
parse match ["/" | end]]]
Marcus
------------------------------------
If you find that life spits on you
calm down and pretend it's raining