Computing.Net > Forums > Programming > please check me this batch

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

please check me this batch

Reply to Message Icon

Name: maxbre
Date: June 9, 2009 at 07:18:25 Pacific
OS: Windows XP
CPU/Ram: 2 gb
Subcategory: Batch
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: June 9, 2009 at 09:22:24 Pacific
Reply:

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.

0

Response Number 2
Name: maxbre
Date: June 9, 2009 at 12:18:50 Pacific
Reply:

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


0

Response Number 3
Name: IVO
Date: June 9, 2009 at 12:57:06 Pacific
Reply:

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


0

Response Number 4
Name: maxbre
Date: June 9, 2009 at 23:57:12 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: please check me this batch

please verify for me this www.computing.net/answers/programming/please-verify-for-me-this/17706.html

C homework - can someone check me? www.computing.net/answers/programming/c-homework-can-someone-check-me/7954.html

Please Help me in VB www.computing.net/answers/programming/please-help-me-in-vb/7830.html