Emacs: Delete Backup in Current Dir Recursively 🚀

By Xah Lee. Date: . Last updated: .

here's a command to delete all emacs backup files~ in current dir and all subdirs.

(defun xah-list-emacs-backup ()
  "List file names ending in tilde ~ , in current dir, recursively.
Return a list of file paths.
Version: 2023-09-13"
  (interactive)
  (let ((xpaths (directory-files-recursively default-directory "~$"))
        (xbuf (generate-new-buffer "*emacs backup files*")))
    (display-buffer xbuf)
    (mapc (lambda (x) (princ (format "%s\n" x) xbuf)) xpaths)))

(defun xah-delete-emacs-backup ()
  "Delete files whose name ends in ~ , in current dir, recursively.
Version: 2023-09-13 2024-01-19 2024-01-21"
  (interactive)
  (let ((xpaths (directory-files-recursively default-directory "~$"))
        (xbuf (get-buffer-create "*emacs backup files*" t)))
    (pop-to-buffer xbuf)
    (erase-buffer)
    (mapc (lambda (x) (insert x "\n")) xpaths)
    (when (y-or-n-p (format "Delete in %s" default-directory))
      (mapc 'delete-file xpaths))
    xpaths))

Emacs, auto save, backup