ambrevar/file: Add walk+mime, finder+mime.
parent
e6e0d806d2
commit
90b121d53c
|
@ -130,6 +130,10 @@ Second value is the list of directories, third value is the non-directories."
|
|||
(defvar *finder-include-directories* t
|
||||
"When non-nil `walk' include directories.")
|
||||
|
||||
(export-always '*finder-constructor*)
|
||||
(defvar *finder-constructor* #'file
|
||||
"Function that takes a path and returns a `file'-like object.")
|
||||
|
||||
(export-always 'walk)
|
||||
(defun walk (root &rest predicates)
|
||||
"List FILES (including directories) that satisfy all PREDICATES.
|
||||
|
@ -140,8 +144,9 @@ Without PREDICATES, list all files."
|
|||
(constantly t) (constantly t)
|
||||
(lambda (subdirectory)
|
||||
(setf result (nconc result
|
||||
(let ((subfiles (mapcar #'file (append (if *finder-include-directories* (list subdirectory) nil)
|
||||
(uiop:directory-files subdirectory)))))
|
||||
(let ((subfiles (mapcar *finder-constructor*
|
||||
(append (if *finder-include-directories* (list subdirectory) nil)
|
||||
(uiop:directory-files subdirectory)))))
|
||||
(if predicates
|
||||
(delete-if (lambda (file)
|
||||
(notany (lambda (pred) (funcall pred file))
|
||||
|
@ -215,3 +220,11 @@ See `%description'."
|
|||
|
||||
(defun file+mime (path)
|
||||
(make-instance 'file+mime :path path))
|
||||
|
||||
(defun walk+mime (root &rest predicates)
|
||||
(let ((*finder-constructor* #'file+mime))
|
||||
(apply #'walk root predicates)))
|
||||
|
||||
(defun finder+mime (root &rest predicates)
|
||||
(let ((*finder-constructor* #'file+mime))
|
||||
(apply #'finder root predicates)))
|
||||
|
|
Loading…
Reference in New Issue