Supporting glob patterns at any level would be handy. I started to
implement something which I've included below but before I complete it:

1. Is there a multi-level glob implementation in some other egg? The glob
that comes with posix only handles the pattern in the top level. I didn't
find anything in searching the eggs.

2. Does anyone have an implementation they can share?

3. If I complete the implementation below can it be added to posix or
should I create an egg?

(define (multi-glob pathspec)
  (let* ((path-parts (string-split pathspec "/" #t)))
    (if (null? path-parts)
        '()
        (let loop ((parts  (cdr path-parts))
                   (result (let ((p (car path-parts)))
                             (if (string=? p "")
                                 '("/")
                                 (glob (car path-parts))))))
          (if (null? parts)
              result
              (let* ((part (car parts))
                     (rem  (cdr parts)))
                (loop rem
                      (apply append
                             (map (lambda (curr)
                                    (let ((new (string-append curr "/"
part)))
                                      (if (and (directory? curr)
                                               (file-read-access? curr))
                                          (glob new)
                                          '())))
                                  result)))))))))
~

~

-- 
--
Complexity is your enemy. Any fool can make something complicated.
It is hard to keep things simple. - Richard Branson.

Reply via email to