chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: It would be nice if glob "/*/*" worked


From: Matt Welland
Subject: Re: It would be nice if glob "/*/*" worked
Date: Thu, 21 Nov 2019 09:24:37 -0700

Improved version:

(define (multi-glob pathspec)
  (let* ((path-parts (intersperse (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)))
     (cond
      ((and (directory? curr)(file-read-access? curr))
(glob new))
      ((member part '("." ".." "/")) new)
      (else '()))))
 result)))))))))

On Thu, Nov 21, 2019 at 3:25 AM Matt Welland <address@hidden> wrote:
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.


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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]