There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop dma driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor motherboard network networking outlook outlook 2003 outlook 2007 outlook express pio problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
DOS/PDA/Other
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Operating Systems > DOS/PDA/Other >
DOS Batch Programming


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
f4cepl4nt's Avatar
Junior Member with 1 posts.
 
Join Date: Oct 2005
Experience: Advanced
08-Oct-2005, 10:34 PM #1
DOS Batch Programming
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's Avatar
Computer Specs
Senior Member with 322 posts.
 
Join Date: Aug 2004
Location: Cairo, Egypt
Experience: Intermediate+ to Advanced
09-Oct-2005, 06:47 AM #2
Hi,
LOL, It is so much simpler than you believe... :LOL:

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...
__________________
I should have learnt C# a long time ago! It's a powerful language, and it's much better in .NET 2.0.
Internet Explorer 6 is the worst browser ever, Get FireFox now! | Get Opera!
At the VERY least Get Internet Explorer 7 !
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 11:14 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.