# DOS Batch Programming



## f4cepl4nt (Oct 9, 2005)

Hey, if anyone knows how to do this I have a question. Is it possible to filter a specific...ehh...ok you know what this question is hard to explain, I'll just give an example of what I want.

I want to use the set command to find that huge list of variables, then use that to find the root drive on a computer. Like this:

set > variables.txt
findstr "SystemDrive" "variables.txt" (now from here im confused as to what I'd do)

should I do something like this to save the output??
set %x%=findstr "SystemDrive" "variables.txt"
or would that screw it up? Basically what I want to be able to do is use code to find out the root disk letter, eg. C:, then save that to a variable. Any help?


----------



## n7Epsilon (Aug 27, 2004)

Hi,
LOL, It is so much simpler than you believe...  

Here's the deal:
In Windows XP/2000 Console (using FINDSTR in your post indicates this), (and also in DOS), the value of any variable can directly be accessed using %VariableName%...

eg:
Open a CMD.EXE window in WindowsXP and type:

set MyName=f4cepl4nt
Echo Hi! %MyName% It is easy to do, don't worry.

You will get a response:
"Hi! f4cepl4nt It is easy to do, don't worry"

Note: On all Windows XP/2000 machines there is a group of predefined variables that are automatically set by the system...

eg: %SystemDrive% always points to the root folder of the drive the current Windows installation is running from (eg: D, %SystemRoot% always points to the Windows folder of the current running Windows installation (eg: C:\WINDOWS)....

To see this, type set > variables.txt, and read variables.txt...

These predefined variables come in extremely useful...

Final Note: "Echo %MyName%" will produce a response "f4cepl4nt"
BUT: "Echo %%MyName%%" (notice the double percentage marks) will produce response "%MyName%"

Also, at the end of your batchfile (especially in DOS), don't forget to unload the variables you use (eg: set MyName=) to remove the MyName variable from memory...

In WindowsXP it is easier, you just put "setlocal" at the beginning of the batch file before setting any variables, and put "endlocal" at the end and XP will unload them for you...


----------

