cmd script involving delayed variable expansion in NT4? - Windows NT

This is a discussion on cmd script involving delayed variable expansion in NT4? - Windows NT ; 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 ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: cmd script involving delayed variable expansion in NT4?

  1. cmd script involving delayed variable expansion in NT4?

    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

  2. Re: cmd script involving delayed variable expansion in NT4?

    Matt Greer wrote:
    > 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


    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


  3. Re: cmd script involving delayed variable expansion in NT4?

    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/Com.../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" wrote in message
    news:dfd58f68.0307020643.7dd6d77c@posting.google.c om...
    > 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




+ Reply to Thread