tags:

views:

22

answers:

1

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)))
+3  A: 

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.

Demosthenex
Thanks so much!
pinkwerks