Emacs Lisp: Get Dired Marked Files

By Xah Lee. Date: . Last updated: .

To get marked files in dired, use dired-get-marked-files

Then, you can map a function to all the files.

;; apply a function to dired's marked files

(require 'dired)

(defun xah-open-dired-marked ()
  "Open marked files in dired."
  (mapc 'find-file (dired-get-marked-files))

;; test
;; M-x dired, then mark some files, then M-x xah-open-dired-marked

;; replace find-file to your own function
ErgoEmacs mascot-s276x226
Buy Xah Emacs Tutorial

Practical Elisp ⭐

Writing Command

Writing Script