Xah Talk Show 2023-09-13 Emacs Lisp Coding, Empty Trash, List Empty Files

xah talk show 2023-09-13 2zBr
xah talk show 2023-09-13 2zBr
(defun xah-empty-trash ()
  "Empty trash, on Microsoft Windows, Mac, Linux.
Version: 2023-09-13"
  (interactive)
  (cond
   ((eq system-type 'windows-nt)
    (shell-command (format "pwsh -Command Clear-RecycleBin -Force;")))
   ((eq system-type 'gnu/linux) nil)
   ((eq system-type 'darwin) nil)
   (t nil)))

(defun xah-list-emacs-backup ()
  "List emacs backup files~ in current dir, recursively.
In lisp code, 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 emacs backup files~ in current dir, recursively.
Version: 2023-09-13"
  (interactive)
  (let ((xpaths (xah-list-emacs-backup)))
    (when (y-or-n-p (format "Delete in %s" default-directory))
      (mapc 'delete-file xpaths))
    xpaths))

(defun xah-list-empty-files ()
  "List empty files in current dir, recursively.
Version: 2023-09-13"
  (interactive)
  (let ((xpaths (directory-files-recursively default-directory "."))
        (xemptyFiles (list))
        (xbuf (generate-new-buffer "*empty files*")))
    (mapc
     (lambda (x)
       (when
           (eq 0 (file-attribute-size (file-attributes x)))
         (push x xemptyFiles)))
     xpaths)
    (display-buffer xbuf)
    (mapc (lambda (x) (princ (format "%s\n" x) xbuf)) xemptyFiles)))

(defun xah-delete-empty-files ()
  "Delete empty files in current dir, recursively.
Version: 2023-09-13"
  (interactive)
  (let ((xfiles (xah-list-empty-files)))
    (mapc 'delete-file xfiles)))