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?
Join Stack Overflow to learn, share knowledge, and build your career.
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?
This can easily be done using dired
:
Enter a dired view of your directory
Switch to writable dired mode (wdired-change-to-wdired-mode
): C-xC-q
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_\1
RET
Finish editing (wdired-finish-edit
): C-xC-s or C-cC-c
You're done!
m
(or * s
to mark all files in buffer) and run % R
to rename with regexp.
– jafrog
Jun 5 '13 at 12:03
run-foo.sh
, foo.conf
and init-foo-script
and you wanted to replace foo with bar, it is simpler to just do a replace in the buffer than concoct a regex that matches the correct value and properly replaces it. That said, in the described scenario, % R does seem like it'd work just fine.
– elarson
Jun 29 '16 at 16:04
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.