Re: How do implement this wildcard?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




"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


.



Relevant Pages

  • Re: Unexpected retrieved value in Environment Varaibles
    ... dirty little hardware inventory script that I call from the main login ... Pentium4 CPU 3.00GHz Winnipeg ... WPGAGEDKAREN-H2 Microsoft Windows XP Professional Intel ... I tend to obtain my environmental variables like so: ...
    (microsoft.public.scripting.vbscript)
  • Re: system ("source ...");
    ... I want to set some environmental variables in order to be visible ... > to the script children programs. ... I consider putting them in a different perl script using %ENV. ... one Perl file in another, you want either do, require, or use, again ...
    (perl.beginners)
  • Re: creating Environment variable during logon script
    ... script, I can get it to create the variable during execution however, ... Here are a few options to create non-transient environmental variables: ... For Each str In oWsShell.Environment ...
    (microsoft.public.scripting.vbscript)
  • Defining environment variables and cgi scripts
    ... I have a cgi script I want apache to execute for me. ... The problem I'm having is I don't know how to include editional environmental variables that the script requires. ... How do I add a variable called PAYMENTIC_HOME to the list of environment variables that perl knows about when executing a script under apache? ...
    (Debian-User)
  • Re: How do implement this wildcard?
    ... The "x" makes the script robust so that it does not fail in the line below ... for environmental variables, ... Every process, whether it is a Command Processor or some other executable, ... You need to execute a ...
    (microsoft.public.windows.server.scripting)