Re: How do implement this wildcard?
- From: "Al Dunbar" <alandrub@xxxxxxxxxxx>
- Date: Thu, 23 Apr 2009 17:57:15 -0600
"Pegasus [MVP]" <news@xxxxxxxxxxxxx> wrote in message
news:OIR5DmAxJHA.3832@xxxxxxxxxxxxxxxxxxxxxxx
"Synapse Syndrome [KGB]" <synapse@xxxxxxxxxxxxxxxxxxxx> wrote in message
news:OICNLPAxJHA.5516@xxxxxxxxxxxxxxxxxxxxxxx
Pegasus [MVP] <news@xxxxxxxxxxxxx> wrote:
I want a .cmd script to check that %1 is a UNC server name and goto
something else.
You can probably see what I want to do, so how do I do it correctly?
if [%1] == [\\*] goto:UNC
Here you go:
@echo off
set parm=%1x
if [%parm:~0,2%]==[\\] echo UNC
Ah, thanks a lot Pegasus. Got it working now, but I do not really know
what that does. Like what is that x supposed to mean? I have read about
this method of spoofing wildcards, by making environmental variables,
before, but it was not explained in any way that I could understand.
Have you got any link that explain this?
The temporary variables disappear once that CMD instance is closed,
right? Or is there a way to clean them up at the end of the script?
The "x" makes the script robust so that it does not fail in the line below
in case you invoke it without a parameter. Any character or string would
do, e.g. set parm=%1Synapse
My script does not really "spoof" wildcards - it merely uses the substring
function available at the console. Since the substring function only works
for environmental variables (at least as far as I know), the script must
assign %1 to an environmental variable.
Every process, whether it is a Command Processor or some other executable,
inherits its environmental variables from the parent that invokes it. When
that process closes then all variables are lost. You need to execute a
special command if you wish to preserve a variable and make it available
for other processes.
The script determines whether or not the parameter is a UNC, but it is not
necessarily a "UNC server name", as originally requested. Whether a UNC
string is completely valid as in \\server\share or
\\server\share\path\file.ext or partly valid as in \\server would be
significantly more difficult to determine using batch alone. That said, the
specific requirements might not require a completely rigorous solution.
Another technique that might be useful here applies to batch script
parameters andFOR loop variables. For example the output from this
statement:
for %%F in (C:\whatever.txt x.y \\server) do echo/[%%~dF]
should be:
[C:]
[C:]
[\\]
In otherwords, the "drive" component of a UNC is the leading "\\".
/Al
.
- References:
- How do implement this wildcard?
- From: Synapse Syndrome [KGB]
- Re: How do implement this wildcard?
- From: Pegasus [MVP]
- Re: How do implement this wildcard?
- From: Synapse Syndrome [KGB]
- Re: How do implement this wildcard?
- From: Pegasus [MVP]
- How do implement this wildcard?
- Prev by Date: Re: VBScript that will stop then start two services and pop up a message box afterwards
- Next by Date: Re: Logon script help
- Previous by thread: Re: How do implement this wildcard?
- Index(es):
Relevant Pages
|