Solved

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

Posted on 2004-09-03
7
464 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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 …
I use more than 1 computer in my office for various reasons. Multiple keyboards and mice take up more than just extra space, they make working a little more complicated. Using one mouse and keyboard for all of my computers makes life easier. This co…
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.

863 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now