Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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 EnableDelayedExpansionfor /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
)
)
::endthis 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

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.

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

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

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

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |