Megatest

multi-glob.scm at [c8e58c2956]
Login

File multi-glob.scm artifact 1e40166643 part of check-in c8e58c2956


(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)))))))))