On this page... (hide)
M-x dirednavigate to directory
- navigate cursor to first file
C-x (- enter macro definition
- RET - open file (we’re in dired mode)
- <all processing here>
C-x C-s- save
C-x k- close
[Cursor down]- down to next file
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
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
(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: ")
(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
When you get done running it, you’ll be left in a
dired buffer with the OLD filenames.
No comments yet.