-1

This may appear as a duplicate question but it is not. My problem is a little different. Actually, I had a folder with a lot of mp4 files and I wanted to suffix each of the file names with GOOD. Seeing answers to the previous question I did something and ended up actually suffixing with .mp4good. Thus a file originally a.mp4 became a.mp4good.mp4 instead of aGOOD.mp4 (what I actually wanted). Luckily, all these files are running but the names are not what I wanted. I request help how to get what I want from this point. I used rename command in DOS from the folder containing these files.

DavidPostill
  • 153,128
  • 77
  • 353
  • 394
  • 1
    Welcome to Super User! Please note that [SU] is not a free script/code writing service. If you tell us what you have tried so far (include the scripts/code you are already using) and where you are stuck then we can try to help with specific problems. You should also read [How do I ask a good question?](https://superuser.com/help/how-to-ask). – DavidPostill Sep 02 '16 at 11:49
  • As I told before, I followed the answer in original question on the same topic. so I did execute at the command the following: rename *.mp4 *GOOD.mp4 – Seetha Rama Raju Sanapala Sep 02 '16 at 13:12
  • That doesn't help when you don't link to the original question ... – DavidPostill Sep 02 '16 at 13:13
  • As I told before, I followed the answer in original question on the same topic. so I did execute at the command the following: rename *.mp4 *GOOD.mp4 and I did not get what I wanted. Instead of a.mp4 becoming aGOOD.mp4 it became amp4GOOD,mp4. I want now that amp4GOOD,mp4 becomes aGOOD.mp4 – Seetha Rama Raju Sanapala Sep 02 '16 at 13:20
  • The original question link is http://superuser.com/questions/961999/how-to-rename-multiple-files-by-adding-or-removing-suffix-or-prefix-in-windows – Seetha Rama Raju Sanapala Sep 02 '16 at 13:20
  • Sorry, a small error: Instead of a.mp4 becoming aGOOD.mp4 it became a.mp4GOOD,mp4. I want now that a.mp4GOOD,mp4 becomes aGOOD.mp4 – Seetha Rama Raju Sanapala Sep 02 '16 at 13:22
  • @SeethaRamaRajuSanapala - The accepted answer to that linked question is completely WRONG! You should disregard it. – dbenham Sep 02 '16 at 14:27

1 Answers1

1

As you discovered, the syntax you used to append a suffix to the base name was incorrect. An explanation as to why can be found at How does the Windows RENAME command interpret wildcards?. That link also has the correct syntax to append to the base name:

ren *.mp4 ??????????????????GOOD.*

There must be enough ? to match the length of the longest base name.

Note that if you have some starting names of the form a.b.mp4, then the above will yield aGOOD.b.mp4. If you want a.bGOOD.mp4, then you need more than a simple REN command. You could use

for %F in (*.mp4) do @ren "%F" "%~nFGOOD.mp4"

If you put the command in a batch script then you must double the percents

@echo off
for %%F in (*.mp4) do ren "%%F" "%%~nFGOOD.mp4"

Currently you have names of the form a.mp4GOOD.mp4, and you want aGOOD.mp4.

The solution is:

ren *.mp4GOOD.mp4 ??????????????????GOOD.mp4

If some names have more than two dots, then again you will need more than a simple REN command.

for %A in (*.mp4GOOD.mp4) do @for %B in ("%~nA") do @ren "%B" "%~nBGOOD.mp4

Remember to double the percents if you put the command in a batch script.

dbenham
  • 11,194
  • 6
  • 30
  • 47