Use dired and macros to process multiple files
http://www.ftrain.com/util_emacs_hints.html
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- saveC-x k- close[Cursor down]- down to next fileC-x )@ - exit macro definition [@C-x u <n> C-x e
- execute last-defined-macro <n> times
dolist
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
new-ls-dir
n
c)
(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)))))
(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
new-ls-dir
n
c)
(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
Tags
Comments
No comments yet.
Add Comment




