Link to home
Start Free TrialLog in
Avatar of marxbalz
marxbalz

asked on

How to Assign Drive Space total\used to a variable?

Hi Gurus,
   How do i assign the Drive capacity and space used to a variable from a DOS batch file? Do we have a command
that would do this.

Any input would be appreciated.

thank you
Avatar of Robnhood
Robnhood

I can get use

dir /s | find "bytes free"

to display available disk space, but I am not sure where to take this from here.
Avatar of sirbounty
What operating system are you using?
Avatar of marxbalz

ASKER

WINDOWS 2000 ADVANCED SERVER and some NT 4.0 Servers also.
for /f "usebackq tokens=3 delims= " %i in (`dir ^| find "bytes free"`) do @set FreeSpace=%i

This will set the environment variable "freespace" equal to the free space value returned by dir
Important to note if you are not familiar with the for command, that the single quotes just inside the parenthesis are backquotes - the unshifted ~ on most US keyboards
backquote=`
apostrophe='
ASKER CERTIFIED SOLUTION
Avatar of sirbounty
sirbounty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanx.  Happy to help! : )