Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

cmd script involving delayed variable expansion in NT4?

2 views
Skip to first unread message

Matt Greer

unread,
Jul 2, 2003, 10:43:08 AM7/2/03
to
Hello,

The following code snippet works fine in Win2K and probably XP, but
what is equivalent code in NT4?

---
set CLP=.
for %%x in (.\lib\*.jar) do set CLP=!CLP!;%%x
---

So afterwards CLP is equal to all the jar files in the lib directory,
seperated by a semicolon (ie, making a Java classpath).

This doesn't work in NT4 because it relies on a feature only
introduced in Win2K, the ability to reevaluate CLP on each iteration
of the loop. In NT4 CLP is set to "." at the beginning and stays that
value the duration of the script.

I've searched everywhere and read many batch scripting references
(almost all just cover very basic things) and am still stuck. If
anyone has an idea I'd appreciate it. Thank you.

Thanks

Phil Robyn

unread,
Jul 2, 2003, 1:22:15 PM7/2/03
to

Maybe something like

set CLP=.
for %%x in (.\lib\*.jar) do call :sub %%x
goto :EOF
:sub
set CLP=%CLP%;%1
goto :EOF


--
Phil Robyn
Univ. of California, Berkeley

u n z i p m y a d d r e s s t o s e n d e - m a i l

Matt Greer

unread,
Jul 3, 2003, 9:45:11 AM7/3/03
to
Phil Robyn <zipp...@uclink.berkeley.edu> wrote in message
> Maybe something like
>
> set CLP=.
> for %%x in (.\lib\*.jar) do call :sub %%x
> goto :EOF
> :sub
> set CLP=%CLP%;%1
> goto :EOF

That worked great. Thanks!

Matt

guard

unread,
Jul 16, 2003, 7:50:58 AM7/16/03
to
The .Mount/\Command ".ForExpand" will expand variables at execution time,
providing the same functionality as "EnableDelayedExpansion" while
performing CONSISTENTLY under NT/2K/XP/K3 using the general syntax

%.ForExpand% %%A IN ('SET VariableName') DO ([Command] %%B)

%%A = VariableName
%%B = Dynamically calculated CONTENTS of VariableName

*******

Using your example:

1. SET CLP=.
2. FOR %%x IN (.\lib\*.jar) DO @(
3. %.ForExpand% %%y IN ('SET CLP') DO @(
4. (SET CLP=%%z;%%x)
5. )
6. )


These self-documenting lines will produce a semicolon delimited list of
files matching

.\lib\*.jar

and store those file names in the variable %CLP%.

See the .ForExpand page at
(http://TheSystemGuard.com/MtCmds/CommandShorthand/ForExpand.htm) for
color-keyed examples.

*******
Notes:

1. .Mount/\Commands are constructed using ONLY builtin
commands common to all four platforms (NT/2K/XP/K3).
2. .M/\C's are NOT case sensitive. Mixed case is used
for visual clarity only.
3. The Advanced NT/2K/XP/K3 Command Library (ntlib.cmd)
provides over 100 resources to assist with
writing and documenting cross-platform scripts,
including 57 .Mount/\Commands. You can obtain it
(for FREE) at (http://ntlib.com).

*******

-tsg
____________________________________________________________
TheSystemGuard.com | BoomingOrFuming.com | MountCommands.com
Free and "Almost Free" Knowledge for Windows System Admins!

"Matt Greer" <mgre...@yahoo.com> wrote in message
news:dfd58f68.03070...@posting.google.com...

0 new messages