1.

Solve : C Drive space?

Answer»

Hi,

I am using windows XP.

I need to create a batch file to check the c:drive space and display the result as available space free space and utilized space.

CHKDSK command does not help me to do so.

Can you tell me the command that will help me to do so...??

Thanks vbscript
Code: [Select]Set objFSO = CreateObject("Scripting.FileSystemObject")
Set colDrives = objFSO.Drives
For Each objDrive in colDrives
If objDrive.DriveLetter = "C" Then
Wscript.Echo "Available space: " & objDrive.AvailableSpace & " bytes"
Wscript.Echo "Free space: " & objDrive.FreeSpace & " bytes"
Wscript.Echo "Total size: " & objDrive.TotalSize
End If
Next
save as script.vbs and on command line

c:\test> cscript /nologo script.vbshey....no i do not want a vb code...i have absolutely no idea with visual basic...i was looking for a bat file with batch commands...is that possible..?In this case the VBScript is the better solution, concise, straightforward, and uses named data.

Quote

CHKDSK command does not help me to do so

It should. All the information you need is produced by chkdsk.

Code: [Select]@echo off
for /f "tokens=1-2" %%i in ('chkdsk c: ^| find /i "total disk space"') do (echo Total Space: %%i %%j)
for /f "tokens=1-2" %%i in ('chkdsk c: ^| find /i "kb available on disk"') do (echo Free Space: %%i %%j)

Be careful what you wish for. This batch solution eats up some clock time.



hey thanks sidewinder..

Ok so u suggest VB RIGHT..but i have no prior knowledge of VB.

I wanted to write a script that will connect to the sever os and check the c drive space on the server machine...will VB work there?If the server's C: drive is mapped to your system, the VBScript solution that was posted should work fine after changing the drive letter.

If not, the FileSystemObject is available only for local drives. Instead you'd need to use the Windows Management Interface (WMI).

Oh god these terms are Greek to me... you don't speak greek, doesn't mean you can't speak greek. Quote from: Sidewinder on April 30, 2008, 08:34:24 AM
Code: [Select]@echo off
for /f "tokens=1-2" %%i in ('chkdsk c: ^| find /i "total disk space"') do (echo Total Space: %%i %%j)
for /f "tokens=1-2" %%i in ('chkdsk c: ^| find /i "kb available on disk"') do (echo Free Space: %%i %%j)

Be careful what you wish for. This batch solution eats up some clock time.

Less time if you make chkdsk run once, REDIRECTING its output to a file, and do all the fancy FIND stuff on the file, a LOT more time if there are any errors on the disk that need fixing. PS He asked for used space as well

df1.bat...

Code: [Select]@echo off
REM show available space free space and utilized space.
REM informative message to user
echo Running chkdsk c: (please wait)
REM Redirect output to file
REM Avoids running chkdsk 3 times
chkdsk c: > chkdsk.txt
echo Completed chkdsk.
echo Displaying desired output
echo 1. Total disk space:
REM use FIND to show desired lines of text
type chkdsk.txt | find "KB total disk space"
echo 2. Available space:
type chkdsk.txt | find "available on disk" | find /v "allocation"
echo 3. Used disk space:
type chkdsk.txt | find "files" | find "KB"
Code: [Select]D:\>df1
Running chkdsk c: (please wait)
Completed chkdsk.
Displaying desired output
1. Total disk space:
26724095 KB total disk space.
2. Available space:
11980504 KB available on disk.
3. Used disk space:
14527556 KB in 106148 files.




I'm posting this for all our Greek members:

Code: [Select]On Error Resume Next

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
Const GroupDigits = -1

strComputer ="servername" 'Change to server name
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk Where DeviceID = 'C:'", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)

For Each objItem In colItems
WScript.Echo "Drive: " & objItem.DeviceID
WScript.Echo "Size: " & FormatNumber(objItem.Size,0,,,GroupDigits)
WScript.Echo "Used: " & FormatNumber(objItem.Size - objItem.FreeSpace,0,,,GroupDigits)
WScript.echo "Free: " & FormatNumber(objItem.FreeSpace,0,,,GroupDigits)
Next

Remarkably, it's a trade off. Either batch code that looks like hieroglyphics from King Tut's tomb or VBScript that looks like Greek.
Thank you everybody for your valuable inputs..I am soon going to learn to speak greek..yes and you are right
" If i dont speak greek does not mean i can't!!"


Sidewinder the code you provided me with is checking space on server side using WMI???

CheersQuote
Sidewinder the code you provided me with is checking space on server side using WMI???

Yes, you'll need to replace servername in this line:

strComputer ="servername" 'Change to server name

To get the data from the local machine, replace servername with a dot (.) otherwise you can use the name of any computer on your network. KEEP the quotes.

Most of the code in a WMI script is BOILERPLATE. The challenge is to find the class that contains the data you need.

Good luck. Thank you so much.........just one question is it possible to create this script using Batch files?Quote from: sd on May 01, 2008, 11:11:46 AM
Thank you so much.........just one question is it possible to create this script using Batch files?

ghostdog74 doesn't "do" batch files. Even if that's what you asked for. Do try to keep up!
Quote from: sd on May 01, 2008, 11:11:46 AM
Thank you so much.........just one question is it possible to create this script using Batch files?

Batch code is not designed for remote execution although there are third party programs like psexec in the PS-Tools toolkit that may help. On a network, it may be worth your time to investigate what VBScript or any of the other Windows script languages offer in the way of remote communications.

In answer to your question, you could use a batch file to launch the VBScript.

Good luck.

PS. VBScript and JScript come free as part of Windows. Most of the others are free but need to be downloaded.


Discussion

No Comment Found