Questions about scripting are not OT here, they are frequent.

 

set abc=\\servername\users\username

for /f "delims=\ tokens=1" %%f in ("%abc%") do echo %%f

 

Carl

 

From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Friday, August 29, 2008 10:16 AM
To: NT System Admin Issues
Subject: CMD scripting question

 


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". I can strip off the leading 2
backslashes by: 

_HomeFolder="\\servername\users\username" (actually, I read this value from
a file) 
SET _Offset=2 
SET _Chars=11 
_Server=!_HomeFolder:~%_Offset%,%_Chars%! 

1. I'm having problems storing the value of this substr. I'm not getting
"servername\users\username". Not sure why; I can use that fragment in an IF
statement, and it works. 

2. I found a little utility that will return the position of one string in
another, which I should be able to use to do another substr to isolate the
servername. I'd still need to store it someplace (see problem #1) 

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 "\". 

So any clues, pointers, semi-vitrolic abuse appreciated. Better ways, other
utilities, other examples, etc. 

-- 
Michael Leone
Network Administrator, ISM
Philadelphia Housing Authority
2500 Jackson St
Philadelphia, PA 19145
Tel:  215-684-4180
Cell: 215-252-0143
<mailto:[EMAIL PROTECTED]>

 

 

~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~

Reply via email to