From xradiograph

Emacs: Multiple File Processing

Use dired and macros to process multiple files


  1. M-x dired navigate to directory
  2. navigate cursor to first file
  3. C-x ( - enter macro definition
  4. RET - open file (we’re in dired mode)
  5. <all processing here>
  6. C-x C-s - save
  7. C-x k - close
  8. [Cursor down] - down to next file
  9. C-x )@ - exit macro definition
    [@C-x u <n> C-x e
    - execute last-defined-macro <n> times




See Introduction to Programming in Emacs Lisp - 11.2


Serial Rename



This little code provide a way to rename file sequentially and safely.


To sort the files correctly, you have to set start to 101 if you have a set of files bigger than 100.


This code is part of Lisp:Thumb-page.el


;;rename all files of rep matching ext sequentially

(defun tv-serial-rename (dir ext name start)
  "Rename sequentially a set of file with the extension ext
in a repertory dir with the name name + the startnumber start"

  (interactive "fDir: \nsExt(no dot): \nsName: \nnStart: ")
  (find-file dir)
  (let (ls-dir
  (setq ls-dir (file-expand-wildcards (format "*.%s" ext) t))
  (setq new-ls-dir nil)
  (setq n 0)
  (while (< n (length ls-dir))
    (if (< start 10)
        (push (concat dir name (format "%03d" start) "." ext) new-ls-dir)
      (push (concat dir name (format "%03d" start) "." ext) new-ls-dir))
    (setq start (+ start 1))
    (setq n (+ n 1)))
  (setq ls-dir (reverse ls-dir))
  (setq c 0)
  (dolist (i ls-dir)
    (rename-file i (nth c new-ls-dir))
    (setq c (+ c 1)))))


NOTE: original code has been updated to force three-digit numberig; eg 001..099+


When you get done running it, you’ll be left in a dired buffer with the OLD filenames.

See Also




Emacs Macro Dired

Retrieved from
Page last modified on July 01, 2008, at 02:28 PM