[Top][All Lists]

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

[Chicken-users] Question about find-files

From: Ivan Raikov
Subject: [Chicken-users] Question about find-files
Date: Mon, 05 Nov 2007 10:27:24 +0900
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux)

Hi all,

   I have noticed that the find-files procedure ignores all
subdirectories it finds in the target directory, and I wondered why
that is, since it is inconsistent with the Unix find command. So is
this a bug or a feature? Also, would it be possible to add an option
to include dot files, similar to the directory procedure? Thanks,


P.S.: Here is a variant of find-files that includes subdirectories:

(define find-files
  (let ([glob glob]
        [string-match string-match]
        [make-pathname make-pathname]
        [directory? directory?] )
    (lambda (dir pred . action-id-limit)
      (let-optionals action-id-limit
          ([action (lambda (x y) (cons x y))] ; we want cons inlined
           [id '()]
           [limit #f] )
        (##sys#check-string dir 'find-files)
        (let* ([depth 0]
                (cond [(not limit) (lambda _ #t)]
                      [(fixnum? limit) (lambda _ (fx< depth limit))]
                      [else limit] ) ]
                (if (or (string? pred) (regexp? pred))
                    (lambda (x) (string-match pred x))
                    pred) ] )
          (let loop ([fs (glob (make-pathname dir "*"))]
                     [r id] )
            (if (null? fs)
                (let ([f (##sys#slot fs 0)]
                      [rest (##sys#slot fs 1)] )
                  (cond [(directory? f)
                         (cond [(member (pathname-file f) '("." "..")) (loop 
rest r)]
                               [(lproc f)
                                (loop rest
                                      (fluid-let ([depth (fx+ depth 1)])
                                        (loop (glob (make-pathname f "*")) 
                                              (if (pproc f) (action f r) r)) ) 
) ]
                               [else (loop rest (if (pproc f) (action f r) r))] 
) ]
                        [(pproc f) (loop rest (action f r))]
                        [else (loop rest r)] ) ) ) ) ) ) ) ) )

reply via email to

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