%@if[DEFINED

Charles Dye

Super Moderator
Staff member
May 20, 2008
3,552
46
Albuquerque, NM
prospero.unm.edu
#2
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,.]
 
#3
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