Reputation: 21433
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?
Upvotes: 42
Views: 10729
Reputation: 919
This technique, which I discovered on the internet, is highly beneficial.
It enables you to perform actions, such as running macros, like you edit text files. Once you make changes on the screen and save it as file, they will be automatically applied to the filename.
Alt+x dired to go to the directory.
Alt+x dired-toggle-read-only 【Ctrl+x Ctrl+q】.
Then, just edit the file names. (You can use Alt+x query-replace or Alt+x query-replace-regexp [see Emacs: Find Replace in Current File] or rectangle commands. [see Emacs: Edit Column Text, Rectangle Commands])
When done, wdired-finish-edit 【Ctrl+c Ctrl+c】 to commit the changes.
To abort, Alt+x w dired-abort-changes
or【Ctrl+c Ctrl+k】
Reference: http://xahlee.info/emacs/emacs/rename_file_pattern.html
Upvotes: 3
Reputation: 796
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.
Upvotes: 5
Reputation: 20238
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!
Upvotes: 84