Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs Dired rename many files

Tags:

emacs

dired

How to rename from:

VAR1_1F_text.txt
VAR2_1F_text.txt
VAR3_2F_text.txt

to

1F_VAR1_text.txt
1F_VAR2_text.txt
2F_VAR3_text.txt

How to switch parts of filenames?

like image 872
PascalVKooten Avatar asked Apr 08 '13 14:04

PascalVKooten


People also ask

How do I rename a lot of files at once?

To rename multiple files from File Explorer, select all the files you wish to rename, then press the F2 key. The name of the last file will become highlighted. Type the new name you wish to give to every file, then press Enter.

Is there a program that can rename multiple files at once?

PowerRename is a bulk renaming tool that enables you to: Modify the file names of a large number of files, without giving all of the files the same name. Perform a search and replace on a targeted section of file names. Perform a regular expression rename on multiple files.


2 Answers

This can easily be done using dired:

  1. Enter a dired view of your directory

  2. Switch to writable dired mode (wdired-change-to-wdired-mode): C-xC-q

  3. Edit the file names listing as if it were a normal buffer (for example using a keyboard macro or a rectangular selection or query-replace). Here is a regexp-based solution:

    C-M-%\(VAR.\)_\(..\)RET\2_\1RET

  4. Finish editing (wdired-finish-edit): C-xC-s or C-cC-c

You're done!

like image 93
François Févotte Avatar answered Sep 17 '22 14:09

François Févotte


You could also use Magnar Sveen's multiple-cursors from here, github link.

Switch to writable dired, select the files you want to rename, M-x mc/edit-lines. This should create multiple cursor each with its own kill history.

like image 32
ᐅdevrimbaris Avatar answered Sep 19 '22 14:09

ᐅdevrimbaris