Walk a directory/Recursively: Difference between revisions

Add traversal order control
(Add traversal order control)
Line 700:
=={{header|Common Lisp}}==
{{libheader|CL-FAD}}
This example uses the <code>CL-FAD</code> library to achieve compatibility where the ANSI CL standard leaves ambiguities about pathnames. Quicklisp is used to ensure it is loaded. Traversal is depth-first unless <code>:depth-first-p nil</code> is passed.
<lang lisp>(defunql:quickload mapc:cl-directory-tree (fn directoryfad)
(defun mapc-directory-tree (fn directory &key (depth-first-p t))
(dolist (entry (cl-fad:list-directory directory))
(unless depth-first-p
(funcall fn entry)))</lang>
(when (cl-fad:directory-pathname-p entry)
(mapc-directory-tree fn entry))
(when depth-first-p
(funcall fn entry)))</lang>
(funcall fn entry))))
</lang>
 
<lang lisp>CL-USER> (mapc-directory-tree (lambda (x)
Anonymous user