For Command and Sys Variables

  • Thread starter Thread starter Tom Sibley
  • Start date Start date
T

Tom Sibley

I need to pull apart a variable. I know it's my lack of understanding with
the FOR command that's holding me back, so if anyone knows of a good web
site that explains FOR better then FOR /?, please let me know.

System variable is %USERNAME% (FName_LName)
The deliminator is "_"
I want to convert FName to one variable and LName to another variable. I
will later be using the two variables to create a folder name.

For /f "Tokens=1-2 Delims=_ " %%a in ('%USERNAME%') do (Set FName=%%a& Set
LName=%%b)
If Exist _%FName%-%LName% Goto :End
MD _%FName%-%LName%
 
Tom said:
I need to pull apart a variable. I know it's my lack of understanding with
the FOR command that's holding me back, so if anyone knows of a good web
site that explains FOR better then FOR /?, please let me know.

System variable is %USERNAME% (FName_LName)
The deliminator is "_"
I want to convert FName to one variable and LName to another variable. I
will later be using the two variables to create a folder name.

For /f "Tokens=1-2 Delims=_ " %%a in ('%USERNAME%') do (Set FName=%%a& Set
LName=%%b)
If Exist _%FName%-%LName% Goto :End
MD _%FName%-%LName%

Use double quotes instead of apostrophes:

For /f "Tokens=1-2 Delims=_" %%a in ("%USERNAME%") do ...
 
Tom Sibley said:
I need to pull apart a variable. I know it's my lack of understanding with
the FOR command that's holding me back, so if anyone knows of a good web
site that explains FOR better then FOR /?, please let me know.

An easy to understand example is here:

(http://TheSystemGuard.com/Booming/THE FIRING ISSUE - 20030108.htm)

-tsg

/-----------------+---------------+----------------------\
| COMPATIBILITY | CLARITY | SPEED |
| Write code ONCE | Make it clear | THEN...Make it fast! |
\-----------------+---------------+----------------------/
400+ command-line resources using ONLY native NT commands!
(http://TheSystemGuard.com/default.asp#MasterCommandList)
 
Back
Top