batch file programing copying variables

May 31, 2010 at 02:22:19
Specs: Windows XP
Hi all

I'm wrinting a simple batch to call some
command line applicacion that requires
reading a file and use the same name (without
the extension) to process the file and create an output file.

I've tried to do so in a for loop getting the file
names, copying in a different variable and
replacing the extension for the new one.

Out of a loop this seems to work

@echo off
set a=pic01.pgm
echo %a%
@echo off
set b=%a:~0,-3%txt
echo %b%

but once I try it within like

FOR %%files IN (*.pgm) DO(
SET new=%%files:~0,-3%txt
echo %%new% >> Names.log

it prints just a list of %new

any hint??

See More: batch file programing copying variables

Report •

May 31, 2010 at 02:33:28
For variables are a special case, single character variables that :~x,x and :str=rep won't work for. Their are however other modifiers that are helpful.

Code blocks and %vars% can have their own issues....

This may be what your after:

FOR %%a IN (*.pgm) DO (
    >> Names.log echo %%~na.txt

Report •

May 31, 2010 at 04:07:55
Thanks Judago

That did the trick

Report •

Related Solutions

Ask Question