How do you Appending a File Name?

November 15, 2010 at 12:25:16
Specs: Windows 7
I have a large number of files that I need to append in the folder: C:\Users\Alan\Desktop\MOVEVOL 8 16 - 31\2010

All the files that are there are files that have been split ending with the file extension ".001", ".002"
".003", ".004" and so on.

I am trying to convert the files into png's, but here is an example of my problem:

I have the files 1234.001, 1234.002, 1234.003, 1234.004 that I need to convert to .png

I have tried using the following batch code to do this:

ren *.001 *.png
ren *.002 *.png
ren *.003 *.png
ren *.004 *.png

When converting the files to .png I need to rename them to the following: 1234_001.png, 1234_002.png, 1234_003.png, 1234_004.png so that there will not be a name conflict.

from looking on this site and others I have tried to create my own code that does not seem to be work:

IF EXIST *.002 FOR %%A IN ('dir C:\Users\Alan\Desktop\MOVEVOL 8 16 - 31\2010') DO RENAME %%~nA 002.png

Can some please help me out with this problem, because in the C:\Users\Alan\Desktop\MOVEVOL 8 16 - 31\2010 folder I have 1000's of files that I need to rename and convert so doing this by hand would be horrible.

Thanks


See More: How do you Appending a File Name?

Report •

#1
November 15, 2010 at 12:37:03
@echo off & setLocal EnableDELAYedeXpansion

for /f "tokens=* delims= " %%a in ('dir/b') do (
set ext=%%~Xa
set ext=!ext:~1!
echo ren %%a %%~Na_!ext!.png
)


=====================================
Life is too important to be taken seriously.

M2


Report •

#2
November 15, 2010 at 12:48:27
Thank you for the quick reply

I tried your code:

@echo off & setLocal EnableDELAYedeXpansion

for /f "tokens=* delims= " %%a in ('dir/b') do (
set ext=%%~Xa
set ext=!ext:~1!
echo ren %%a %%~Na_!ext!.png
)

It seemed to run without any errors (i really couldn't tell because it all went so fast), but none of my files were renamed or converted any ideas what went wrong?


Report •

#3
November 15, 2010 at 12:55:11
You need to remove the "echo" on line 6 for it to actually go through with the renaming.

Can I put a question here?


Report •

Related Solutions

#4
November 15, 2010 at 12:56:04
If you run it at the prompt you'll see it's ECHOing the REN.

You can take out the ECHO.


=====================================
Life is too important to be taken seriously.

M2


Report •

#5
November 15, 2010 at 13:02:43
wow I am stupid.

It worked like a CHAMP Thank You!

If I wanted to learn about batch programming is there a website or a book that you would recommend?


Report •

#6
November 15, 2010 at 13:04:00
Yep. This one.


=====================================
Life is too important to be taken seriously.

M2


Report •

Ask Question