Reorder file names in Emacs

I have a package of files with the same format, say bmp , file name 0.bmp 1.bmp ... 99.bmp , I want to change the file names, for example 0.bmp to 99.bmp , 1.bmp to 98.bmp and etc., do emacs do this in dired-mode ? I am using emacs on windows.

+4
source share
3 answers

You can use Mx wdired-change-to-wdired-mode to create an editable buffer. After that, a simple macro keyboard with a counter , starting at the end of the buffer, should do the trick for you.

If you do not want to use a macro, an alternative would be:

 Mx replace-regexp Replace regexp: ^[0-9]+ Replace regexp with \,(- 99 \#&) 
+7
source

May be a quick dirty answer, not a general one:

First: Cx Cq in dired-mode ;

Second: M-: yank and RET fragment:

 (progn (beginning-of-buffer) (while (re-search-forward "\\([0-9]+\\).bmp" nil t) (replace-match (format "%d.bmp" (- 99 (string-to-number (match-string 1)))) nil nil))) 

Third: Cc Cc to save changes and make.

+2
source

I'm not sure about dired-mode , but you can execute a simple script in the *scratch* buffer. Since you are replacing existing file names with different names, I recommend that you first rename all ant files, and then start with these names:

  (progn (dotimes (i 100) (let ((file-name (concat (number-to-string i) ".bmp"))) (rename-file file-name (concat "old" file-name)))) (dotimes (i 100) (let ((file-name-old (concat "old" (number-to-string i) ".bmp")) (file-name-new (concat (number-to-string (- 99 i)) ".bmp"))) (rename-file file-name-old file-name-new)))) 

If you copy this to the *scratch* buffer and, after the expression you press Cx Ce , this code will do it for you.

+1
source

All Articles