Help with passing variable

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
dsumanik

Help with passing variable

#1 Post by dsumanik » 13 Nov 2006 18:28

Hello all my first post here, Im having a little trouble with a script im working on. Specifically, i need to know how to pass the info in a text file to a variable i create, I am somewhat new to batch scripting and i have tried everything but i just cant seem to figure it out.

This script will only be used in the windows XP console.

For an example, in it's simplest form this is what im after, i can probably take it to more complicated levels once i know how to do it:

:: output something from the console then send to txt file
DIR | Find "bytes free" > bytes.txt

:: asign the string inside the text file to a variable
SET BYTES = "the string inside bytes.txt"

::display the value of the string
echo %BYTES%

do you even need the intermediate text file? is this even possible?

DosItHelp
Expert
Posts: 239
Joined: 18 Feb 2006 19:54

#2 Post by DosItHelp » 13 Nov 2006 19:22

dsumanik,

No intermediate file needed.
Try:

Code: Select all

FOR /f "tokens=3 delims= " %%a in ('"dir|find "bytes free""') do set free=%%a
echo.%free%


Optionally use this function:
http://www.dostips.com/DtCodeCmdLib.php#kBytesFree

DOS IT HELP? :wink:

dsumanik

#3 Post by dsumanik » 13 Nov 2006 20:16

Jeez man, someone needs to pay you thats fricken awesome thanks alot!

alright lets get tricker, what about using it in this sense:

SET Node=%ComputerName%
WMIC.EXE /Node:%Node% LogicalDisk Where DriveType="3" Get DeviceID,FreeSpace | FIND "C:" > BYTES.TXT
SET BYTESBEFORE='BYTES.TXT'
echo %BYTESBEFORE%

DosItHelp
Expert
Posts: 239
Joined: 18 Feb 2006 19:54

#4 Post by DosItHelp » 15 Nov 2006 19:21

dsumanik,
What is the output of WMIC.EXE?
Do you have an example :?:

Post Reply