Computing.Net > Forums > Programming > Splitting content of env var in for loop

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.

Splitting content of env var in for loop

Reply to Message Icon

Name: rovf
Date: October 26, 2009 at 05:06:29 Pacific
OS: Windows 2000
Product: Microsoft Windows professional 2000
Subcategory: Batch
Tags: for, batch, split
Comment:

I have a variable containing some words separated by one space, like this

set VAR=word1 word2 word3

Is it possible to have a FOR loop which loops over the word? Something similar in spirit to

rem call mybatch word1
rem call mybatch word2
rem etc.
for %%i in (%VAR%) do call mybatch %%i

only that written in this way, it's syntactically not valid.



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: October 26, 2009 at 05:36:55 Pacific
Reply:

@echo off & setLocal EnableDELAYedExpansion

set VAR=word1 word2 word3

for /f "tokens=1-3 delims= " %%a in ("!VAR!") do (
call mybatch %%a
call mybatch %%b
call mybatch %%c
)


=====================================
Helping others achieve escape felicity

M2


1

Response Number 2
Name: rovf
Date: October 27, 2009 at 05:25:29 Pacific
Reply:

This did not work. For example, executing the following Batch file:

@echo off
setlocal ENABLEDELAYEDEXPANSION
set PROD_DIRNAME_IALL=I1 I2
for %d in (%PROD_DIRNAME_IALL%) do echo xxx %%d

produces the error message

"PROD_DIRNAME_IALLd" ist syntaktisch an dieser Stelle nicht verarbeitbar.

which means that there is a syntax error in the FOR statement.


0

Response Number 3
Name: Mechanix2Go
Date: October 27, 2009 at 22:30:53 Pacific
Reply:

"This did not work"

%d should be %%d


=====================================
Helping others achieve escape felicity

M2


1

Response Number 4
Name: rovf
Date: October 28, 2009 at 06:08:42 Pacific
Reply:

Indeed - thanks a lot!!!!!


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Using a Modulus Help synchronise 2 folder stru...


Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Splitting content of env var in for loop

count in for loop in dos www.computing.net/answers/programming/count-in-for-loop-in-dos/16609.html

single per (.) in for loop batch www.computing.net/answers/programming/single-per-in-for-loop-batch-/17766.html

Variables in For loops, Batch www.computing.net/answers/programming/variables-in-for-loops-batch/17037.html