Pardon the OT question; if there's a better place to ask, please direct me.
So here's my problem .. I have this CMD shell script (not VBScript or
PowerShell), and what I need to do is some string manipulation.
Specifically:
I need to strip off the leading 2 characters from a string, and then I need
to locate the position of a special character in the string. So I have this
value:
\\servername\users\username
What I want to do is to isolate "servername".
Rewriting the script as VBSript or PowerShell isn't really an option yet, as
I am not proficient enough in those to do this.
So what I need to do is parse the string, and return everything from
position 3 to the location of the first "\". I can then use that value
later in an IF statement,
I have this:
_Server="ThatServer"
SET _Offset=3
SET _Chars=11
FOR /F "DELIMS=, SKIP=1 TOKENS=1-6" %%A IN (HomeFolders.txt) DO (
SET _HomeFolder=%%E
IF /I "!_HomeFolder:~%_Offset%,%_Chars%!" NEQ "!_Server!" (
I then do stuff here. This works, but only because the IF statement is
comparing "servername\users\username" to "ThatServer", and of course
failing. Ideally, what I want is just the servername. (I get these values by
extracting them from my Win2000 AD, using the ADFIND program, and
redirecting output to a file. I then read that file back in.
So any clues, pointers, semi-vitrolic abuse appreciated. Better ways, other
utilities, other examples, etc.
|