Page 1 of 1

Help with passing variable

Posted: 13 Nov 2006 18:28
by dsumanik
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?

Posted: 13 Nov 2006 19:22
by DosItHelp
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:

Posted: 13 Nov 2006 20:16
by dsumanik
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%

Posted: 15 Nov 2006 19:21
by DosItHelp
dsumanik,
What is the output of WMIC.EXE?
Do you have an example :?: