UP | HOME

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:

1. Blog colors

  • ffecb3

Author: kyle (kyle@imladris)

Date: 2025-04-13 Sun 00:00

Emacs 30.1 (Org mode 9.7.11)

Validate