please check me this batch

June 9, 2009 at 07:18:25
Specs: Windows XP, 2 gb
please, does anyone can help me with this batch: why it is failing the string substitution which is supposed to do as assigned to the variable "new"; in the output instead of the "new" string there is very simply nothing!

:: start
@echo off & setLocal EnableDelayedExpansion

for /l %%a in (1,1,366) do (
set /A idx+=1
set fno=!idx!
if !idx! lss 10 set fno=0!fno!
if !idx! lss 100 set fno=0!fno!
if !idx! lss 1000 set fno=0!fno!

for /f "tokens=* delims=" %%b in (gst_!fno!.upl) do (
set new="met_!fno!.met"
set str=%%b
set str=!str:abcde.met=%new%!
echo !str! >> gst_!fno!.tmp
)
)
::end

this is somehow a follow up to one of my previous thread
http://www.computing.net/answers/pr...

I hope I'm not boring you all to death with this staff

thanks


See More: please check me this batch

Report •


#1
June 9, 2009 at 09:22:24
In a For loop you can't define an enviroment variable and then refer to it without declaring that var as dynamic. You set up new and then refer to %new%, as it is a inner variable. You have to change strategy here to put your code at work. So replace


for /f "tokens=* delims=" %%b in (gst_!fno!.upl) do (
  set new="met_!fno!.met"
  set str=%%b
  set str=!str:abcde.met=%new%!
  echo !str! >> gst_!fno!.tmp
)
)
::end

    with

for /f "tokens=* delims=" %%b in (gst_!fno!.upl) do (
  set new="met_!fno!.met"
  set str=%%b
  call :SUB
  echo !str! >> gst_!fno!.tmp
)
)
goto :EOF

:SUB
  set str=!str:abcde.met=%new%!
goto :EOF
::end

To manage delayed expansion is much like to ride a rocket plane.

Report •

#2
June 9, 2009 at 12:18:50
ok ivo

now I see, as usual I'm messing up with the use of dynamic variables and the delayed expansion...

but you have to admit that this time, thanks to all your past great lessons, I was quite close to the right solution...

tomorrow with a clearer mind (hopefully), I will extensively test the code on my data...

thanks a lot (you saved me hours of work!) and have a good night

ciao

max


Report •

#3
June 9, 2009 at 12:57:06
Unfortunately software engineering is not engineering: i,e. Engineering (civil, mechanical and so on...) admits tolerance (up to 50 per cent in aerospace tecnology) while Software must be perfect to work correctly. So to be close does not suffice.

Nice dreams

Ivo


Report •

Related Solutions

#4
June 9, 2009 at 23:57:12
yeah, probably that's why sw engeneering is so entangling: because of that tiny things that seems "to rule" the world!

by the way, I tested the code and it's working fine!

thanks

m


Report •


Ask Question