Sunday, November 25, 2018

removal of suffixes from multiple files in windows - not duplicate


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.


Answer



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.


No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...