Append a common text to a group of files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
rick2010
Posts: 2
Joined: 06 Jul 2010 12:01

Append a common text to a group of files

#1 Post by rick2010 » 06 Jul 2010 12:14

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

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Append a common text to a group of files

#2 Post by aGerman » 06 Jul 2010 13:03

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

rick2010
Posts: 2
Joined: 06 Jul 2010 12:01

Re: Append a common text to a group of files

#3 Post by rick2010 » 06 Jul 2010 17:02

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

Post Reply