Page 1 of 1

Append a common text to a group of files

Posted: 06 Jul 2010 12:14
by rick2010
I've been racking my brains on this one. It should be easy but I think I'm missing something obvious.
I have a group of files (ex. .mp3's) and I would like to add an alphanumeric prefix to the whole group of files in a folder.
Example:
1234567890.mp3
2345678901.mp3
3456789012.mp3
etc.

I would like to prefix all of them with two or three digit characters so the result would be:

Example:
psr1234567890.mp3
psr2345678901.mp3
psr3456789012.mp3
etc.

A simple rename command will strip the filename down to eight characters with my prefix.

Is there a dos script routine I can use to accomplish this?
Thanks - Rick

Re: Append a common text to a group of files

Posted: 06 Jul 2010 13:03
by aGerman
Rick, you could use a FOR loop.
Have a look at this small code

Code: Select all

@echo off &setlocal
set /p "pre=Enter your prefix: "
for /f "delims=" %%a in ('dir /a-d /b *.mp3') do ren "%%a" "%pre%%%a"


This should work if you would place the batch file into the same folder of your .mp3's.

Regards
aGerman

Re: Append a common text to a group of files

Posted: 06 Jul 2010 17:02
by rick2010
Hey! It works! Thanks!
I had to change the second line though.

set pre="rtt"

With rtt being the pre text.

I don't know if it had something to do with XP Pro as the OS.

Anyway, it works and I thank you for the help.

Rick