开发者

capturing cl-fad:walk-directory output for finding files

I've wrestled with this for hours I'm trying to write a find file function similar to the unix command. The long and short of it boils down not understanding why I can't return a proper value from the cl-fad:walk-directory function as 开发者_开发百科a list (cl-fad is here http://weitz.de/cl-fad/).

I'm trying something like this:

(cl-fad:walk-directory "/tmp/" #'(lambda (file) (format nil "~a" file))))

But get '; No value' from the REPL. However the below substituting 'format nil'...

(cl-fad:walk-directory "/tmp/" #'(lambda (file) (format t "~a" file)))

Prints out all the files in my /tmp/ directory (and below) to STDOUT. However I haven't been able to collect that output into a list.

I've tried the below with no success.

(loop for f in (cl-fad:walk-directory 
                "/tmp/" 
                #'(lambda (file) (format t "~a" file)))
   collect (list f)))


The walk function doesn't collect return values like mapcar, it just applies. You'll need to save the output yourself somewhere, perhaps appending to a global list or stack.

(let (files)
       (cl-fad:walk-directory "/tmp/" #'(lambda (x) (push (namestring x) files)))
       files)

Note that namestring converts from path objects to just a filename.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜