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_\1RET -
Finish editing (
wdired-finish-edit): C-xC-s or C-cC-c
You’re done!