Appending string to a filename using cmd

Koing

Elite Member <br> Super Moderator<br> Health and F
Oct 11, 2000
16,843
2
0
Hi guys.

My bro needs some help.

We have say 5-50 files in a directory and he wants to append a string to the file names using cmd as he only has access to that.

E.G.

files
Mr A and Mrs B.doc
Mr C and Mrs D.doc
Mr E and Mrs F.doc
Mr G and Mrs H.doc

He wants to append " - C note Buy 221207"

So file name becomes
Mr A and Mrs B - C note Buy 221207.doc
Mr C and Mrs D - C note Buy 221207.doc
Mr E and Mrs F - C note Buy 221207.doc
Mr G and Mrs H - C note Buy 221207.doc


I've gotten this so far:
From:
Mr A and Mrs B.doc

To:
Mr A and Mrs - C note buy 211207.doc

with this command

rename *.doc *" - C note buy 211207".doc

As you can see it is chopping off the last string value. In the above example B :(

Any ideas? Cheers!

Koing
 

hg403

Member
Jul 7, 2002
40
0
0
This should work, though i'm sure there's a more elegant solution
for /f "delims=." %i in ('dir /b *.doc') do @rename "%i.doc" "%i - C note Buy 221207.doc"
 

Koing

Elite Member <br> Super Moderator<br> Health and F
Oct 11, 2000
16,843
2
0
Originally posted by: hg403
This should work, though i'm sure there's a more elegant solution
for /f "delims=." %i in ('dir /b *.doc') do @rename "%i.doc" "%i - C note Buy 221207.doc"

THANKS a lot mate! MUCH appreciated :D

:thumbsup:

Koing