1.

Solve : Trying to change file extensions?

Answer»

Hi there. I have a tool that will process images from one FORMAT to another. I have the list of filenames to be processed but I'm having difficulty in getting the batch file to run properly the code is:
Code: [Select]for /F "delims=," %%a in (imagelist.lst) do (
set oldname = %%a
set newname =%oldname:.*=%
convert %%a %newname%.jpg
)

but it seems that newname does not set correctly. any Ideas?Be very careful about introducing spaces in a set command. Spaces are actual characters.

The star (*) on the set newname statement does not act as a wildcard. You'll need to spell out exactly what the extension is, or parse the file name to extract the information.

Good luck. Thanks, I changed the spacing and got a better response but it's still reading in a value for newname that was set outside the script. Is there a better way of stripping any extension and replacing it with .jpg ?What is confusing the the comma delimiter. If you have one image name per line then this should work:

Code: [Select]for /F "tokens=1-2 delims=." %%a in (imagelist.lst) do (
convert %%a.%%b %%a.jpg
)

The for statement READS one line from the input file on each loop. If you have multiple image names SEPARATED by commas on each line, you'll need to parse the entire line. This will involve rethinking the structure of the batch file.



Thanks sidewinder, I appreciate the help

I'm new to DOS scripting, coming from UNIX it's hard

OK, I can reformat the input file, at the moment it LOOKS like this :
Code: [Select]Test.eps,
one.png,
two.eps,
So I'm going to knock out the end comma and try your solution on:
Code: [Select]Test.eps
one.png
two.epsThere is no need to change your data. A simple tweak of the batch code will account for the comma:

Code: [Select]for /F "tokens=1-2 delims=.," %%a in (imagelist.lst) do (
convert %%a.%%b %%a.jpg
)

Good luck.
Sidewinder you superstar !!!! Thanks that worked perfectly.

I really appreciate the help. Cheers



Discussion

No Comment Found