removing files
I wanted to clear all non-gcode files off the SD card for my printer (it keeps trying to update the firmware).
So, defining *sd*
to be the path to the SD card:
(defun extension-matches (ext path) (let ((p (if (PATHNAMEP path) (namestring path) path))) (multiple-value-bind (base extension) (uiop:split-name-type p) (declare (ignore base)) (string= ext extension)))) (remove-if (lambda (p) (extension-matches "gcode" p)) (uiop:directory-files *sd*)) (defun remove-file (p) (let ((p (probe-file p))) (when p (delete-file p)))) (mapcar #'remove-file (remove-if (lambda (p) (extension-matches "gcode" p)) (uiop:directory-files *sd*)))
Verifying:
CL-USER> (remove-if (lambda (p) (extension-matches "gcode" p)) (uiop:directory-files *sd*)) nil
Things learned:
- uiop's functions work on a mix of string and pathname
1. Blog colors
- ffecb3