Firstly, take note of JeanPierre's comment -- you're not renaming files by using
convert like that. You're creating new and different files (lower quality ones, although the difference may or may not matter in practice, depending on your use-cases).
Here are a few different options for renaming files in dired using a number sequence. The first two are general techniques for editing text, which are applicable thanks to the excellent
wdired-mode. The third combines dired's rename command with keyboard macro counters.
- C-xC-q (change to editable dired mode; use
C-c C-k to cancel the edit if you mess anything up)
- C-M-% (call
CIMG[0-9]+\.JPG (pattern to match)
\,(format "%02d" (1+ \#)).JPG (replacement)
- ! (replace all; or else you could confirm the replacements individually)
- C-cC-c (to return to normal dired mode, writing the changes)
\,(...) calls an elisp function and uses the result in the replacement text; here we are calling
format on the replacement counter, to which we are first adding one (as it counts from zero).
(It's a shame that
dired-do-rename-regexp doesn't support that, but not a big deal when you're familiar with
Once again in editable dired mode, mark the filenames as a rectangle, delete the rectangle, then use
rectangle-number-lines to insert new contents:
- C-uC-xrN call
rectangle-number-lines with extended argument input
- Start from 1
%02d as the replacement, being sure to remove the default trailing space (or you could use
%02d.JPG, depending on what you actually deleted)
With keyboard macros, in normal dired:
%02d (set kmacro counter format)
- M-1F3 (start recording, initialising counter to 1)
- R (dired rename)
- F3 (insert the current kmacro counter value; the counter then increments)
.JPG RET (remainder of the new filename)
- C-n (next line)
- F4 (repeatedly; first to end recording, and then to repeat the macro)
You can use M-0F4 to repeat the macro as many times as possible.
dired-modebuffer by typing the exclamation point keyboard shortcut:
!You may wish to mark one or more files ahead of time.