Solved

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

Posted on 2004-09-03
7
473 Views
Last Modified: 2011-09-20
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
0
Comment
Question by:marxbalz
7 Comments
 
LVL 1

Expert Comment

by:Robnhood
ID: 11972776
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.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 11972846
What operating system are you using?
0
 

Author Comment

by:marxbalz
ID: 11972977
WINDOWS 2000 ADVANCED SERVER and some NT 4.0 Servers also.
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 95

Expert Comment

by:Lee W, MVP
ID: 11973680
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
0
 
LVL 95

Expert Comment

by:Lee W, MVP
ID: 11973710
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='
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 250 total points
ID: 11973756
You can gain both from chkdsk, although it will take a few moments to run the command:


::-----begin code-----
@echo off
for /f "skip=19 tokens=1,3-4" %%a in ('chkdsk /i /c') do (
if %%b%%c==totaldisk set totDisk=%%a
if %%b%%c==inuse set inUse=%%a
)
::-----end code-------
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 11976025
Thanx.  Happy to help! : )
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Often we come across situations wherein our batch files would be needing to reboot Windows for a variety of reasons. A few of them would be like: (1) Setup files have been updated whose changes can take effect only after a reboot …
Windows 10 is here and for most admins this means frustration and challenges getting that first working Windows 10 image. As in my previous sysprep articles, I've put together a simple help guide to get you through this process. The aim is to achiev…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question