1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

%@if[DEFINED

Discussion in 'Support' started by krischik, Oct 12, 2010.

  1. krischik

    Joined:
    Feb 20, 2009
    Messages:
    46
    Likes Received:
    1
    Being a bit naive I tried the following which did not work:

    Code:
    SET in_Directory=%@If[DEFINED 1,%[1],.]
    I guess %1 qualifies as internal variable which always fails DEFINED so I guess I have to look for an alternative. I just wonder which might be the best alternative.

    Martin
     
  2. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,277
    Likes Received:
    38
    DEFINED is just for environment variables. You might instead do something like this:

    Code:
    set in_directory=%@if[%1. != .,%1,.]
     
  3. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,523
    Likes Received:
    4
    Charles Dye wrote:

    | Quote:
    | Originally Posted by krischik
    || Being a bit naive I tried the following which did not work:
    ||
    ||
    || Code:
    || SET in_Directory=%@If[DEFINED 1,%[1],.]
    || I guess %1 qualifies as
    || internal variable which always fails DEFINED so I guess I have to
    || look for an alternative. I just wonder which might be the best
    || alternative.
    ||
    | DEFINED is just for environment variables. You might instead do
    | something like this:
    |
    |
    | Code:
    | set in_directory=%@if[%1. != .,%1,.]

    Since %1 is always a parameter, whether to a batch file or to an alias,
    if it is not present the parameter count %# is zero. I thus use this form:

    SET in_Directory=%@If[%# GT 0,%1,.]

    Note that this works only for the LAST (or ONLY) parameter of the batch
    file/alias. Much more elaborate parsing is required if an earlier
    parameter's presence is optional.

    BTW, I would use something like @TRUENAME[.] or @FULL[.], rather than
    just .; if there is a possibility that the path name includes special
    characters, I'd use this:

    SET in_Directory=%@quote[%@full[%@If[%# GT 0,%1,.]]]
    --
    HTH, Steve
     

Share This Page