command prompt - rename command

T

Tim

Help. I am trying to rename several humdred files using
the Windows 2000 command prompt and I have been unable to
do so. For example, I need to rename 'image1-
thumbnail.jpg' to 'image1_t.jpg'. So I tried the
following command (among several others) without success:
ren *-thumbnail.jpg *_t.jpg
(the result of that is 'image1-thumbnail.jpg_t.jpg')

Can anyone tell me what I am doing wrong or how to do the
batch renaming?
 
R

Ray at

ren *thumbnail.jpg *t.jpg

That will change:
image1-thumbnail.jpg
image2-thumbnail.jpg
image3-thumbnail.jpg

To:
image1-t.jpg
image2-t.jpg
image3-t.jpg

Ray at work
 
T

Tim

Thanks Ray, that did work (not sure why). Now I just have
to figure out how to get the _ in there.
 
R

Ray at

Ah, I thought the _ was a typo. How about:


ren *thumbnail.jpg *t.jpg
ren *-*.jpg *_*.jpg

Ray at work
 
T

Tim

Hmmm, that didn't work for me. The result is:
image1-t.jpg_.jpg

I'm starting to think it's not possible to do this, but
really, it should be.
 
T

Tom Lavedas

Try this (from the command prompt) ...

for %a in (image*-*.jpg) do (
for /f "tokens=1 delims=-" %b in ("%v") do (
ren %b %b_t.jpg)

Or double the percent signs for use in a batch file.

Or you can use these three rename statements ...

ren image?-*.jpg ??????_t.*
ren image??-*.jpg ???????_t.*
ren image???-*.jpg ????????_t.*

Tom Lavedas
===========
 
M

Matthias Tacke

Tom Lavedas said:
Try this (from the command prompt) ...

for %a in (image*-*.jpg) do (
for /f "tokens=1 delims=-" %b in ("%v") do (
Is that a typo? I think that here ^^%a^^ should be ??
ren %b %b_t.jpg)

Or double the percent signs for use in a batch file.

I had the same construction in mind, but was to slow.
If the first for is used with /R that should climb into
subdirs. To be shure and for testing I would echo the ren
to a file and examine it before executing.
 
T

Tom Lavedas

Yes, that's a typo. I tend to use %%v for my FOR
variable, wherever I use it. However, when I nested the
FOR, I figured I better make it more intuative.
Unfortunately, I made the adjustment from %v to %a on-the-
fly while keying my reply. I didn't test it after my
change. Thanks, Matthias, for fixing my faux pax.

That is ...

for %a in (image*-*.jpg) do (
for /f "tokens=1 delims=-" %b in ("%a") do (
ren %b %b_t.jpg)

Sorry, Tim, if I confused you.

Tom Lavedas
===========
 
T

Tim

No problem Tom. And thanks, you guys are great!
-----Original Message-----
Yes, that's a typo. I tend to use %%v for my FOR
variable, wherever I use it. However, when I nested the
FOR, I figured I better make it more intuative.
Unfortunately, I made the adjustment from %v to %a on-the-
fly while keying my reply. I didn't test it after my
change. Thanks, Matthias, for fixing my faux pax.

That is ...

for %a in (image*-*.jpg) do (
for /f "tokens=1 delims=-" %b in ("%a") do (
ren %b %b_t.jpg)

Sorry, Tim, if I confused you.

Tom Lavedas
===========

.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top