removal of suffixes from multiple files in windows - not duplicate

-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.

Seetha Rama Raju Sanapala

Posted 2016-09-02T11:22:23.630

Reputation: 109

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?.

– DavidPostill – 2016-09-02T11:49:23.187

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 – 2016-09-02T13:12:13.597

That doesn't help when you don't link to the original question ... – DavidPostill – 2016-09-02T13:13:46.963

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 – 2016-09-02T13:20:10.073

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 – 2016-09-02T13:20:30.237

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 – 2016-09-02T13:22:26.027

@SeethaRamaRajuSanapala - The accepted answer to that linked question is completely WRONG! You should disregard it. – dbenham – 2016-09-02T14:27:11.753

Answers

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

Posted 2016-09-02T11:22:23.630

Reputation: 9 212

@dbenham : Thank you so much! You have given more than what I asked for. Pointers and references. – Seetha Rama Raju Sanapala – 2016-09-02T15:21:30.703